|
73 | 73 | #include "DockAreaTitleBar.h"
|
74 | 74 | #include "DockAreaTabBar.h"
|
75 | 75 | #include "FloatingDockContainer.h"
|
| 76 | +#include "DockComponentsFactory.h" |
| 77 | + |
76 | 78 |
|
77 | 79 |
|
78 | 80 | //============================================================================
|
@@ -142,6 +144,25 @@ static QIcon svgIcon(const QString& File)
|
142 | 144 | }
|
143 | 145 |
|
144 | 146 |
|
| 147 | +//============================================================================ |
| 148 | +class CCustomComponentsFactory : public ads::CDockComponentsFactory |
| 149 | +{ |
| 150 | +public: |
| 151 | + using Super = ads::CDockComponentsFactory; |
| 152 | + ads::CDockAreaTitleBar* createDockAreaTitleBar(ads::CDockAreaWidget* DockArea) const override |
| 153 | + { |
| 154 | + auto TitleBar = Super::createDockAreaTitleBar(DockArea); |
| 155 | + auto CustomButton = new QToolButton(DockArea); |
| 156 | + CustomButton->setToolTip(QObject::tr("Help")); |
| 157 | + CustomButton->setIcon(svgIcon(":/adsdemo/images/help_outline.svg")); |
| 158 | + CustomButton->setAutoRaise(true); |
| 159 | + int Index = TitleBar->indexOf(TitleBar->button(ads::TitleBarButtonTabsMenu)); |
| 160 | + TitleBar->insertWidget(Index + 1, CustomButton); |
| 161 | + return TitleBar; |
| 162 | + } |
| 163 | +}; |
| 164 | + |
| 165 | + |
145 | 166 | //============================================================================
|
146 | 167 | static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
|
147 | 168 | {
|
@@ -202,28 +223,29 @@ static ads::CDockWidget* createEditorWidget(QMenu* ViewMenu)
|
202 | 223 | return DockWidget;
|
203 | 224 | }
|
204 | 225 |
|
| 226 | + |
205 | 227 | //============================================================================
|
206 | 228 | static ads::CDockWidget* createTableWidget(QMenu* ViewMenu)
|
207 | 229 | {
|
208 |
| - static int TableCount = 0; |
209 |
| - QTableWidget* w = new QTableWidget(); |
210 |
| - ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++)); |
211 |
| - static int colCount = 5; |
212 |
| - static int rowCount = 30; |
213 |
| - w->setColumnCount(colCount); |
214 |
| - w->setRowCount(rowCount); |
215 |
| - for (int col = 0; col < colCount; ++col) |
216 |
| - { |
217 |
| - w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1))); |
218 |
| - for (int row = 0; row < rowCount; ++row) |
219 |
| - { |
220 |
| - w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1))); |
221 |
| - } |
222 |
| - } |
223 |
| - DockWidget->setWidget(w); |
224 |
| - DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg")); |
225 |
| - ViewMenu->addAction(DockWidget->toggleViewAction()); |
226 |
| - return DockWidget; |
| 230 | + static int TableCount = 0; |
| 231 | + QTableWidget* w = new QTableWidget(); |
| 232 | + ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Table %1").arg(TableCount++)); |
| 233 | + static int colCount = 5; |
| 234 | + static int rowCount = 30; |
| 235 | + w->setColumnCount(colCount); |
| 236 | + w->setRowCount(rowCount); |
| 237 | + for (int col = 0; col < colCount; ++col) |
| 238 | + { |
| 239 | + w->setHorizontalHeaderItem(col, new QTableWidgetItem(QString("Col %1").arg(col+1))); |
| 240 | + for (int row = 0; row < rowCount; ++row) |
| 241 | + { |
| 242 | + w->setItem(row, col, new QTableWidgetItem(QString("T %1-%2").arg(row + 1).arg(col+1))); |
| 243 | + } |
| 244 | + } |
| 245 | + DockWidget->setWidget(w); |
| 246 | + DockWidget->setIcon(svgIcon(":/adsdemo/images/grid_on.svg")); |
| 247 | + ViewMenu->addAction(DockWidget->toggleViewAction()); |
| 248 | + return DockWidget; |
227 | 249 | }
|
228 | 250 |
|
229 | 251 |
|
@@ -318,7 +340,11 @@ void MainWindowPrivate::createContent()
|
318 | 340 | FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetMovable, false);
|
319 | 341 | FileSystemWidget->setFeature(ads::CDockWidget::DockWidgetFloatable, false);
|
320 | 342 | appendFeaturStringToWindowTitle(FileSystemWidget);
|
| 343 | + |
| 344 | + // Test custom factory - we inject a help button into the title bar |
| 345 | + ads::CDockComponentsFactory::setFactory(new CCustomComponentsFactory()); |
321 | 346 | auto TopDockArea = DockManager->addDockWidget(ads::TopDockWidgetArea, FileSystemWidget);
|
| 347 | + ads::CDockComponentsFactory::resetDefaultFactory(); |
322 | 348 |
|
323 | 349 | // We create a calender widget and clear all flags to prevent the dock area
|
324 | 350 | // from closing
|
|
0 commit comments