Changeset View
Changeset View
Standalone View
Standalone View
src/main/KexiObjectViewWidget.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2003 Lucijan Busch <lucijan@kde.org> | ||||
3 | Copyright (C) 2003-2016 Jarosław Staniek <staniek@kde.org> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Library General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2 of the License, or (at your option) any later version. | ||||
9 | | ||||
10 | This library is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | * Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "KexiObjectViewWidget.h" | ||||
22 | #include "KexiObjectViewTabWidget.h" | ||||
23 | #include <KexiPropertyPaneWidget.h> | ||||
24 | #include <KexiWidgetWidthAnimator.h> | ||||
25 | #include <KexiProjectNavigator.h> | ||||
26 | #include <KexiTester.h> | ||||
27 | #include <KexiStyle.h> | ||||
28 | #include <KexiWindow.h> | ||||
29 | #include <KexiMainWindowIface.h> | ||||
30 | | ||||
31 | #include <KPropertyEditorView> | ||||
32 | #include <KActionCollection> | ||||
33 | | ||||
34 | #include <QHBoxLayout> | ||||
35 | #include <QResizeEvent> | ||||
36 | #include <QSplitter> | ||||
37 | | ||||
38 | | ||||
39 | class KexiObjectViewWidget::Private | ||||
40 | { | ||||
41 | public: | ||||
42 | Private() | ||||
43 | : navigator(0) | ||||
44 | , navigatorWidthAnimator(0) | ||||
45 | , propertyPane(0) | ||||
46 | , propertyPaneWidthAnimator(0) | ||||
47 | , projectNavigatorWidthToSet(-1) | ||||
48 | , propertyPaneWidthToSet(-1) | ||||
49 | { | ||||
50 | } | ||||
51 | KexiProjectNavigator* navigator; | ||||
52 | KexiWidgetWidthAnimator* navigatorWidthAnimator; | ||||
53 | KexiObjectViewTabWidget* tabWidget; | ||||
54 | QPointer<KexiWindow> previouslyActiveWindow; | ||||
55 | KexiPropertyPaneWidget *propertyPane; | ||||
56 | KexiWidgetWidthAnimator* propertyPaneWidthAnimator; | ||||
57 | //QMap<KMultiTabBar::KMultiTabBarPosition, KMultiTabBar*> multiTabBars; | ||||
58 | QSplitter *splitter; | ||||
59 | int projectNavigatorWidthToSet; | ||||
60 | int propertyPaneWidthToSet; | ||||
61 | }; | ||||
62 | | ||||
63 | | ||||
64 | KexiObjectViewWidget::KexiObjectViewWidget(Flags flags) | ||||
65 | : QWidget() | ||||
66 | , d(new Private) | ||||
67 | { | ||||
68 | QHBoxLayout *mainLyr = new QHBoxLayout; | ||||
69 | mainLyr->setContentsMargins(0, 0, 0, 0); | ||||
70 | mainLyr->setSpacing(0); | ||||
71 | setLayout(mainLyr); | ||||
72 | | ||||
73 | d->splitter = new QSplitter(Qt::Horizontal); | ||||
74 | connect(d->splitter, &QSplitter::splitterMoved, | ||||
75 | this, &KexiObjectViewWidget::slotSplitterMoved); | ||||
76 | mainLyr->addWidget(d->splitter); | ||||
77 | | ||||
78 | // Left tab bar | ||||
79 | // KMultiTabBar *mtbar = new KMultiTabBar(KMultiTabBar::Left); | ||||
80 | // mtbar->setStyle(KMultiTabBar::VSNET); | ||||
81 | // mainLyr->addWidget(mtbar); | ||||
82 | // d->multiTabBars.insert(mtbar->position(), mtbar); | ||||
83 | | ||||
84 | if (flags & ProjectNavigatorEnabled) { | ||||
85 | // Project navigator | ||||
86 | // KexiDockableWidget* navDockableWidget = new KexiDockableWidget; | ||||
87 | d->navigator = new KexiProjectNavigator(d->splitter); | ||||
88 | kexiTester() << KexiTestObject(d->navigator, "KexiProjectNavigator"); | ||||
89 | //navDockableWidget->setWidget(d->navigator); | ||||
90 | KexiStyle::setSidebarsPalette(d->navigator); | ||||
91 | d->navigatorWidthAnimator = new KexiWidgetWidthAnimator(d->navigator); | ||||
92 | connect(d->navigatorWidthAnimator, &KexiWidgetWidthAnimator::animationFinished, | ||||
93 | this, &KexiObjectViewWidget::projectNavigatorAnimationFinished); | ||||
94 | } | ||||
95 | | ||||
96 | //d->navDockWidget = new KexiDockWidget(d->navigator->windowTitle(), d->objectViewWidget); | ||||
97 | //d->navDockWidget->setObjectName("ProjectNavigatorDockWidget"); | ||||
98 | //d->objectViewWidget->addDockWidget( | ||||
99 | // applyRightToLeftToDockArea(Qt::LeftDockWidgetArea), d->navDockWidget, | ||||
100 | // Qt::Vertical); | ||||
101 | //navDockableWidget->setParent(d->navDockWidget); | ||||
102 | //d->navDockWidget->setWidget(navDockableWidget); | ||||
103 | | ||||
104 | // Central tab widget | ||||
105 | d->tabWidget = new KexiObjectViewTabWidget(d->splitter, this); | ||||
106 | d->tabWidget->setTabsClosable(true); | ||||
107 | connect(d->tabWidget, &KexiObjectViewTabWidget::currentChanged, | ||||
108 | this, &KexiObjectViewWidget::slotCurrentTabIndexChanged); | ||||
109 | connect(d->tabWidget, &KexiObjectViewTabWidget::tabCloseRequested, | ||||
110 | this, &KexiObjectViewWidget::closeWindowRequested); | ||||
111 | | ||||
112 | if (flags & PropertyPaneEnabled) { | ||||
113 | // Property editor | ||||
114 | d->propertyPane = new KexiPropertyPaneWidget(d->splitter); | ||||
115 | KexiStyle::setSidebarsPalette(d->propertyPane); | ||||
116 | KexiStyle::setSidebarsPalette(d->propertyPane->editor()); | ||||
117 | | ||||
118 | d->propertyPaneWidthAnimator = new KexiWidgetWidthAnimator(d->propertyPane); | ||||
119 | } | ||||
120 | | ||||
121 | // mtbar = new KMultiTabBar(KMultiTabBar::Right); | ||||
122 | // mtbar->setStyle(KMultiTabBar::VSNET); | ||||
123 | // mainLyr->addWidget(mtbar); | ||||
124 | // d->multiTabBars.insert(mtbar->position(), mtbar); | ||||
125 | } | ||||
126 | | ||||
127 | KexiObjectViewWidget::~KexiObjectViewWidget() | ||||
128 | { | ||||
129 | } | ||||
130 | | ||||
131 | KexiProjectNavigator* KexiObjectViewWidget::projectNavigator() const | ||||
132 | { | ||||
133 | return d->navigator; | ||||
134 | } | ||||
135 | | ||||
136 | KexiObjectViewTabWidget* KexiObjectViewWidget::tabWidget() const | ||||
137 | { | ||||
138 | return d->tabWidget; | ||||
139 | } | ||||
140 | | ||||
141 | KexiPropertyPaneWidget* KexiObjectViewWidget::propertyPane() const | ||||
142 | { | ||||
143 | return d->propertyPane; | ||||
144 | } | ||||
145 | | ||||
146 | void KexiObjectViewWidget::slotCurrentTabIndexChanged(int index) | ||||
147 | { | ||||
148 | KexiWindow *window = d->tabWidget->window(index); | ||||
149 | if (!window || (KexiWindow*)d->previouslyActiveWindow == window) { | ||||
150 | return; | ||||
151 | } | ||||
152 | emit activeWindowChanged(window, d->previouslyActiveWindow); | ||||
153 | d->previouslyActiveWindow = window; | ||||
154 | emit currentTabIndexChanged(index); | ||||
155 | } | ||||
156 | | ||||
157 | void KexiObjectViewWidget::setSidebarWidths(int projectNavigatorWidth, int propertyEditorWidth) | ||||
158 | { | ||||
159 | d->projectNavigatorWidthToSet = projectNavigatorWidth; | ||||
160 | d->propertyPaneWidthToSet = propertyEditorWidth; | ||||
161 | } | ||||
162 | | ||||
163 | void KexiObjectViewWidget::resizeEvent(QResizeEvent *e) | ||||
164 | { | ||||
165 | QWidget::resizeEvent(e); | ||||
166 | //qDebug() << "___" << e->size() << size() << isVisible(); | ||||
167 | if (isVisible()) { | ||||
168 | updateSidebarWidths(); | ||||
169 | } | ||||
170 | } | ||||
171 | | ||||
172 | void KexiObjectViewWidget::showEvent(QShowEvent *e) | ||||
173 | { | ||||
174 | QWidget::showEvent(e); | ||||
175 | updateSidebarWidths(); | ||||
176 | } | ||||
177 | | ||||
178 | const int PROJECT_NAVIGATOR_INDEX = 0; | ||||
179 | const int MAIN_AREA_INDEX = 1; | ||||
180 | const int PROPERTY_EDITOR_INDEX = 2; | ||||
181 | | ||||
182 | void KexiObjectViewWidget::updateSidebarWidths() | ||||
183 | { | ||||
184 | QList<int> sizes(d->splitter->sizes()); | ||||
185 | if (sizes.count() <= 1) { | ||||
186 | return; | ||||
187 | } | ||||
188 | //qDebug() << "updateSidebarWidths" << d->projectNavigatorWidthToSet << d->propertyEditorWidthToSet << sizes << d->splitter->width() << isVisible(); | ||||
189 | if (d->projectNavigatorWidthToSet <= 0) { | ||||
190 | if (d->navigator) { | ||||
191 | sizes[PROJECT_NAVIGATOR_INDEX] = d->navigator->sizeHint().width(); | ||||
192 | } | ||||
193 | } else { | ||||
194 | sizes[PROJECT_NAVIGATOR_INDEX] = d->projectNavigatorWidthToSet; | ||||
195 | } | ||||
196 | if (sizes.count() >= (PROPERTY_EDITOR_INDEX+1)) { | ||||
197 | if (d->propertyPane && d->propertyPane->isVisible()) { | ||||
198 | if (d->propertyPaneWidthToSet <= 0) { | ||||
199 | d->propertyPaneWidthToSet = d->propertyPane->sizeHint().width(); | ||||
200 | } | ||||
201 | sizes[PROPERTY_EDITOR_INDEX] = d->propertyPaneWidthToSet; | ||||
202 | sizes[MAIN_AREA_INDEX] = d->splitter->width() - sizes[PROJECT_NAVIGATOR_INDEX] - sizes[PROPERTY_EDITOR_INDEX]; | ||||
203 | } else { | ||||
204 | sizes[PROPERTY_EDITOR_INDEX] = 0; | ||||
205 | sizes[MAIN_AREA_INDEX] = d->splitter->width() - sizes[PROJECT_NAVIGATOR_INDEX]; | ||||
206 | } | ||||
207 | } | ||||
208 | d->splitter->setSizes(sizes); | ||||
209 | //qDebug() << "updateSidebarWidths" << sizes << d->splitter->sizes(); | ||||
210 | } | ||||
211 | | ||||
212 | void KexiObjectViewWidget::getSidebarWidths(int *projectNavigatorWidth, int *propertyEditorWidth) const | ||||
213 | { | ||||
214 | QList<int> sizes(d->splitter->sizes()); | ||||
215 | if (sizes.count() < (PROPERTY_EDITOR_INDEX+1)) { | ||||
216 | *projectNavigatorWidth = -1; | ||||
217 | *propertyEditorWidth = -1; | ||||
218 | return; | ||||
219 | } | ||||
220 | | ||||
221 | //qDebug() << "getSidebarWidths" << d->propertyEditorTabWidget->width(); | ||||
222 | *projectNavigatorWidth = (sizes.count() >= (PROJECT_NAVIGATOR_INDEX+1) && sizes[PROJECT_NAVIGATOR_INDEX] > 0) | ||||
223 | ? sizes[PROJECT_NAVIGATOR_INDEX] : d->projectNavigatorWidthToSet; | ||||
224 | *propertyEditorWidth = (sizes.count() >= (PROPERTY_EDITOR_INDEX+1) && sizes[PROPERTY_EDITOR_INDEX] > 0) | ||||
225 | ? sizes[PROPERTY_EDITOR_INDEX] : d->propertyPaneWidthToSet; | ||||
226 | //qDebug() << "getSidebarWidths" << *projectNavigatorWidth << *propertyEditorWidth; | ||||
227 | } | ||||
228 | | ||||
229 | void KexiObjectViewWidget::slotSplitterMoved(int pos, int index) | ||||
230 | { | ||||
231 | Q_UNUSED(pos) | ||||
232 | //qDebug() << "slotSplitterMoved" << pos << index; | ||||
233 | QList<int> sizes(d->splitter->sizes()); | ||||
234 | if (index == PROJECT_NAVIGATOR_INDEX + 1) { | ||||
235 | if (sizes.count() >= (PROJECT_NAVIGATOR_INDEX+1)) { | ||||
236 | d->projectNavigatorWidthToSet = sizes[PROJECT_NAVIGATOR_INDEX]; | ||||
237 | } | ||||
238 | } else if (index == PROPERTY_EDITOR_INDEX) { | ||||
239 | if (sizes.count() >= (PROPERTY_EDITOR_INDEX+1)) { | ||||
240 | d->propertyPaneWidthToSet = sizes[PROPERTY_EDITOR_INDEX]; | ||||
241 | } | ||||
242 | } | ||||
243 | } | ||||
244 | | ||||
245 | void KexiObjectViewWidget::setProjectNavigatorVisible(bool set) | ||||
246 | { | ||||
247 | QAction *action_show_nav = KexiMainWindowIface::global()->actionCollection()->action("view_navigator"); | ||||
248 | action_show_nav->setChecked(set); | ||||
249 | d->navigatorWidthAnimator->setVisible(set); | ||||
250 | } | ||||
251 | | ||||
252 | void KexiObjectViewWidget::setPropertyPaneVisible(bool set) | ||||
253 | { | ||||
254 | QAction *action_show_propeditor = KexiMainWindowIface::global()->actionCollection()->action("view_propeditor"); | ||||
255 | action_show_propeditor->setChecked(set); | ||||
256 | d->propertyPaneWidthAnimator->setVisible(set); | ||||
257 | } |