Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_tool_options_popup.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2015 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
7
8
9#include <QList>
10#include <QFont>
11#include <QAction>
12#include <QShowEvent>
13#include <QPointer>
14#include <QGridLayout>
15#include <QFrame>
16#include <QLabel>
17#include <QApplication>
18#include <QFontDatabase>
19
20#include <KoDockRegistry.h>
21
22#include <kconfig.h>
23#include <klocalizedstring.h>
24
25
26#include "kis_config.h"
27#include "KisUiFont.h"
28
30{
31public:
32 QFont smallFont;
34
36 QSet<QWidget *> currentAuxWidgets;
37 QWidget *hiderWidget; // non current widgets are hidden by being children of this
38 QGridLayout *housekeeperLayout;
39
40 void recreateLayout(const QList<QPointer<QWidget> > &optionWidgetList)
41 {
42 Q_FOREACH (QPointer<QWidget> widget, currentWidgetList) {
43 if (!widget.isNull() && widget && hiderWidget) {
44 widget->setParent(hiderWidget);
45 }
46 }
47 qDeleteAll(currentAuxWidgets);
48 currentAuxWidgets.clear();
49
50 currentWidgetList = optionWidgetList;
51 if (currentWidgetList.isEmpty()) return;
52
53 // need to unstretch row that have previously been stretched
54 housekeeperLayout->setRowStretch(housekeeperLayout->rowCount()-1, 0);
55
56 int cnt = 0;
57 QFrame *s;
58 QLabel *l;
59 housekeeperLayout->setHorizontalSpacing(0);
60 housekeeperLayout->setVerticalSpacing(2);
61 int specialCount = 0;
62 Q_FOREACH (QPointer<QWidget> widget, currentWidgetList) {
63 if (widget.isNull() || widget->objectName().isEmpty()) {
64 continue; // skip this docker in release build when assert don't crash
65 }
66
67 widget->setMinimumWidth(300);
68
69 if (!widget->windowTitle().isEmpty()) {
70 housekeeperLayout->addWidget(l = new QLabel(widget->windowTitle()), cnt++, 0);
71 currentAuxWidgets.insert(l);
72 }
73 housekeeperLayout->addWidget(widget, cnt++, 0);
74 QLayout *subLayout = widget->layout();
75 if (subLayout) {
76 for (int i = 0; i < subLayout->count(); ++i) {
77 QWidget *spacerWidget = subLayout->itemAt(i)->widget();
78 if (spacerWidget && spacerWidget->objectName().contains("SpecialSpacer")) {
79 specialCount++;
80 }
81 }
82 }
83 widget->show();
84 if (widget != currentWidgetList.last()) {
85 housekeeperLayout->addWidget(s = new QFrame(), cnt++, 0);
86 s->setFrameStyle(QFrame::HLine | QFrame::Sunken);
87 currentAuxWidgets.insert(s);
88 }
89 }
90 if (specialCount == currentWidgetList.count() || qApp->applicationName().contains("krita")) {
91 housekeeperLayout->setRowStretch(cnt, 10000);
92 }
93
94 housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
95 housekeeperLayout->invalidate();
96 }
97
98};
99
100
102 : QWidget(parent)
103 , d(new Private())
104{
105 setObjectName("KisToolOptionsPopup");
106
107 KConfigGroup group( KSharedConfig::openConfig(), "GUI");
108 setFont(KisUiFont::dockFont());
109
110 d->ignoreHideEvents = false;
111
112 d->housekeeperLayout = new QGridLayout(this);
113 d->housekeeperLayout->setContentsMargins(4,4,4,0);
114 d->housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
115 d->hiderWidget = new QWidget(this);
116 d->hiderWidget->setVisible(false);
117}
118
119
124
126{
127 d->recreateLayout(optionWidgetList);
128}
129
130void KisToolOptionsPopup::contextMenuEvent(QContextMenuEvent *e) {
131
132 Q_UNUSED(e);
133}
134
135void KisToolOptionsPopup::hideEvent(QHideEvent *event)
136{
137 if (d->ignoreHideEvents) {
138 return;
139 }
140 QWidget::hideEvent(event);
141}
142
144{
145}
void showEvent(QShowEvent *) override
void hideEvent(QHideEvent *) override
void contextMenuEvent(QContextMenuEvent *) override
KisToolOptionsPopup(QWidget *parent=0)
void newOptionWidgets(const QList< QPointer< QWidget > > &optionWidgetList)
QFont dockFont()
Gets a font with a smallish font size for dock widgets to use.
Definition KisUiFont.cpp:98
QList< QPointer< QWidget > > currentWidgetList
void recreateLayout(const QList< QPointer< QWidget > > &optionWidgetList)