blob: f343e6a1c23a1dc8dd32debf45b6d24d54be9417 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2020 Felix Ernst <[email protected]>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef DOLPHINNAVIGATORSWIDGETACTION_H
#define DOLPHINNAVIGATORSWIDGETACTION_H
#include "dolphinurlnavigator.h"
#include <QSplitter>
#include <QTimer>
#include <QWidgetAction>
#include <memory>
class KXmlGuiWindow;
class QPushButton;
/**
* @brief QWidgetAction that allows to use DolphinUrlNavigators in a toolbar.
*
* This class is mainly a container that manages up to two DolphinUrlNavigator objects so they
* can be added to a toolbar. It also deals with alignment.
*
* The structure of the defaultWidget() of this QWidgetAction is as follows:
* - A QSplitter manages up to two sides which each correspond to one DolphinViewContainer.
* The secondary side only exists for split view and is created by
* createSecondaryUrlNavigator() when necessary.
* - Each side is a QWidget which I call NavigatorWidget with a QHBoxLayout.
* - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton and spacing.
* - Only the primary navigatorWidget has leading spacing. Both have trailing spacing.
* The spacing is there to align the UrlNavigator with its DolphinViewContainer.
*/
class DolphinNavigatorsWidgetAction : public QWidgetAction
{
Q_OBJECT
public:
DolphinNavigatorsWidgetAction(QWidget *parent = nullptr);
/**
* Adds this action to the mainWindow's toolbar and saves the change
* in the users ui configuration file.
* @return true if successful. Otherwise false.
*/
bool addToToolbarAndSave(KXmlGuiWindow *mainWindow);
/**
* The secondary UrlNavigator is only created on-demand. Such an action is not necessary
* for the primary UrlNavigator which is created preemptively.
*
* This method should preferably only be called when:
* - Split view is activated in the active tab
* OR
* - A switch to a tab that is already in split view mode is occuring
*/
void createSecondaryUrlNavigator();
/**
* Notify the primary UrlNavigator of changes in geometry of the ViewContainer it tries to be
* aligned with. Only call this method if there is no secondary UrlNavigator.
*/
void followViewContainerGeometry(int globalXOfPrimary, int widthOfPrimary);
/**
* Notify this widget of changes in geometry of the ViewContainers it tries to be
* aligned with.
*/
void followViewContainersGeometry(int globalXOfPrimary, int widthOfPrimary,
int globalXOfSecondary, int widthOfSecondary);
/**
* @return the primary UrlNavigator.
*/
DolphinUrlNavigator *primaryUrlNavigator() const;
/**
* @return the secondary UrlNavigator and nullptr if it doesn't exist.
*/
DolphinUrlNavigator *secondaryUrlNavigator() const;
/**
* Change the visibility of the secondary UrlNavigator including spacing.
* @param visible Setting this to false will completely hide the secondary side of this
* WidgetAction's QSplitter making the QSplitter effectively disappear.
*/
void setSecondaryNavigatorVisible(bool visible);
private:
/**
* Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers.
* This can only work nicely if up-to-date geometry of ViewContainers is cached so
* followViewContainersGeometry() has to have been called at least once before.
*/
void adjustSpacing();
/**
* In Left-to-right languages the Primary side will be the left one.
*/
enum Side {
Primary,
Secondary
};
/**
* Used to create the navigatorWidgets for both sides of the QSplitter.
*/
QWidget *createNavigatorWidget(Side side) const;
/**
* Used to retrieve the emptyTrashButtons for the navigatorWidgets on both sides.
*/
QPushButton *emptyTrashButton(Side side);
/**
* Creates a new empty trash button.
* @param urlNavigator Only when this UrlNavigator shows the trash directory
* will the the button be visible.
* @param parent Aside from the usual QObject deletion mechanisms,
* this parameter influences the positioning of dialog windows
* pertaining to this trash button.
*/
QPushButton *newEmptyTrashButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const;
enum Position {
Leading,
Trailing
};
/**
* Used to retrieve both the leading and trailing spacing for the navigatorWidgets
* on both sides. A secondary leading spacing does not exist.
*/
QWidget *spacing(Side side, Position position) const;
/**
* Sets this action's text depending on the amount of visible UrlNavigators.
*/
void updateText();
/**
* The defaultWidget() of this QWidgetAction.
*/
std::unique_ptr<QSplitter> m_splitter;
/**
* adjustSpacing() has to be called slightly later than when urlChanged is emitted.
* This timer bridges that time.
*/
std::unique_ptr<QTimer> m_adjustSpacingTimer;
// cached values
int m_globalXOfSplitter;
int m_globalXOfPrimary;
int m_widthOfPrimary;
int m_globalXOfSecondary;
int m_widthOfSecondary;
};
#endif // DOLPHINNAVIGATORSWIDGETACTION_H
|