2 * SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
3 * SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
5 * SPDX-License-Identifier: GPL-2.0-or-later
8 #ifndef DOLPHIN_TAB_PAGE_H
9 #define DOLPHIN_TAB_PAGE_H
16 class DolphinNavigatorsWidgetAction
;
17 class DolphinViewContainer
;
18 class QVariantAnimation
;
20 class DolphinTabPageSplitter
;
27 class DolphinTabPage
: public QWidget
32 explicit DolphinTabPage(const QUrl
& primaryUrl
, const QUrl
& secondaryUrl
= QUrl(), QWidget
* parent
= nullptr);
35 * @return True if primary view is the active view in this tab.
37 bool primaryViewActive() const;
40 * @return True if split view is enabled.
42 bool splitViewEnabled() const;
45 * Enables or disables the split view mode.
47 * @param enabled If true, creates a secondary viewContainer in this tab.
48 * Otherwise deletes it.
49 * @param animated Decides whether the effects of this method call should
50 * happen instantly or be transitioned to smoothly.
51 * @param secondaryUrl If \p enabled is true, the new viewContainer will be opened at this
52 * parameter. The default value will set the Url of the new viewContainer
53 * to be the same as the existing one.
55 void setSplitViewEnabled(bool enabled
, Animated animated
, const QUrl
&secondaryUrl
= QUrl());
58 * @return The primary view container.
60 DolphinViewContainer
* primaryViewContainer() const;
63 * @return The secondary view container, can be 0 if split view is disabled.
65 DolphinViewContainer
* secondaryViewContainer() const;
68 * @return DolphinViewContainer of the active view
70 DolphinViewContainer
* activeViewContainer() const;
73 * Returns the selected items. The list is empty if no item has been
76 KFileItemList
selectedItems() const;
79 * Returns the number of selected items (this is faster than
80 * invoking selectedItems().count()).
82 int selectedItemsCount() const;
85 * Connects a navigatorsWidget to this. It will be connected to the DolphinViewContainers
86 * managed by this tab. For alignment purposes this will from now on notify the
87 * navigatorsWidget when this tab or its viewContainers are resized.
89 void connectNavigators(DolphinNavigatorsWidgetAction
*navigatorsWidget
);
92 * Makes it so this tab and its DolphinViewContainers aren't controlled by any
93 * UrlNavigators anymore.
95 void disconnectNavigators();
97 void insertNavigatorsWidget(DolphinNavigatorsWidgetAction
*navigatorsWidget
);
100 * Marks the items indicated by \p urls to get selected after the
101 * directory DolphinView::url() has been loaded. Note that nothing
102 * gets selected if no loading of a directory has been triggered
103 * by DolphinView::setUrl() or DolphinView::reload().
105 void markUrlsAsSelected(const QList
<QUrl
> &urls
);
108 * Marks the item indicated by \p url to be scrolled to and as the
109 * current item after directory DolphinView::url() has been loaded.
111 void markUrlAsCurrent(const QUrl
& url
);
114 * Refreshes the views of the main window by recreating them according to
115 * the given Dolphin settings.
120 * Saves all tab related properties (urls, splitter layout, ...).
122 * @return A byte-array which contains all properties.
124 QByteArray
saveState() const;
127 * Restores all tab related properties (urls, splitter layout, ...) from
128 * the given \a state.
130 void restoreState(const QByteArray
& state
);
133 * Set whether the tab page is active
136 void setActive(bool active
);
139 void activeViewChanged(DolphinViewContainer
* viewContainer
);
140 void activeViewUrlChanged(const QUrl
& url
);
141 void splitterMoved(int pos
, int index
);
145 * Deletes all zombie viewContainers that were used for the animation
146 * and resets the minimum size of the others to a sane value.
148 void slotAnimationFinished();
151 * This method is called for every frame of the m_expandViewAnimation.
153 void slotAnimationValueChanged(const QVariant
&value
);
156 * Handles the view activated event.
158 * It sets the previous active view to inactive, updates the current
159 * active view type and triggers the activeViewChanged event.
161 void slotViewActivated();
164 * Handles the view url redirection event.
166 * It emits the activeViewUrlChanged signal with the url \a newUrl.
168 void slotViewUrlRedirection(const QUrl
& oldUrl
, const QUrl
& newUrl
);
170 void switchActiveView();
174 * Creates a new view container and does the default initialization.
176 DolphinViewContainer
* createViewContainer(const QUrl
& url
) const;
179 * Starts an animation that transitions between split view mode states.
181 * One of the viewContainers is always being expanded when toggling so
182 * this method can animate both opening and closing of viewContainers.
183 * @param expandingContainer The container that will increase in size
184 * over the course of the animation.
186 void startExpandViewAnimation(DolphinViewContainer
*expandingContainer
);
189 DolphinTabPageSplitter
*m_splitter
;
191 QPointer
<DolphinNavigatorsWidgetAction
> m_navigatorsWidget
;
192 QPointer
<DolphinViewContainer
> m_primaryViewContainer
;
193 QPointer
<DolphinViewContainer
> m_secondaryViewContainer
;
195 DolphinViewContainer
*m_expandingContainer
;
196 QPointer
<QVariantAnimation
> m_expandViewAnimation
;
198 bool m_primaryViewActive
;
199 bool m_splitViewEnabled
;
203 class DolphinTabPageSplitterHandle
: public QSplitterHandle
208 explicit DolphinTabPageSplitterHandle(Qt::Orientation orientation
, QSplitter
*parent
);
211 bool event(QEvent
*event
) override
;
214 void resetSplitterSizes();
216 // Sometimes QSplitterHandle doesn't receive MouseButtonDblClick event.
217 // We can detect that MouseButtonDblClick event should have been
218 // received if we receive two MouseButtonRelease events in a row.
219 bool m_mouseReleaseWasReceived
;
222 class DolphinTabPageSplitter
: public QSplitter
227 explicit DolphinTabPageSplitter(Qt::Orientation orientation
, QWidget
*parent
);
230 QSplitterHandle
* createHandle() override
;
233 #endif // DOLPHIN_TAB_PAGE_H