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
52 // need to unstretch row that have previously been stretched
53 housekeeperLayout->setRowStretch(housekeeperLayout->rowCount()-1, 0);
54
55 int cnt = 0;
56 QFrame *s;
57 QLabel *l;
58 housekeeperLayout->setHorizontalSpacing(0);
59 housekeeperLayout->setVerticalSpacing(2);
60 int specialCount = 0;
61 Q_FOREACH (QPointer<QWidget> widget, currentWidgetList) {
62 if (widget.isNull() || widget->objectName().isEmpty()) {
63 continue; // skip this docker in release build when assert don't crash
64 }
65
66 widget->setMinimumWidth(300);
67
68 if (!widget->windowTitle().isEmpty()) {
69 housekeeperLayout->addWidget(l = new QLabel(widget->windowTitle()), cnt++, 0);
70 currentAuxWidgets.insert(l);
71 }
72 housekeeperLayout->addWidget(widget, cnt++, 0);
73 QLayout *subLayout = widget->layout();
74 if (subLayout) {
75 for (int i = 0; i < subLayout->count(); ++i) {
76 QWidget *spacerWidget = subLayout->itemAt(i)->widget();
77 if (spacerWidget && spacerWidget->objectName().contains("SpecialSpacer")) {
78 specialCount++;
79 }
80 }
81 }
82 widget->show();
83 if (widget != currentWidgetList.last()) {
84 housekeeperLayout->addWidget(s = new QFrame(), cnt++, 0);
85 s->setFrameStyle(QFrame::HLine | QFrame::Sunken);
86 currentAuxWidgets.insert(s);
87 }
88 }
89 if (specialCount == currentWidgetList.count() || qApp->applicationName().contains("krita")) {
90 housekeeperLayout->setRowStretch(cnt, 10000);
91 }
92
93 housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
94 housekeeperLayout->invalidate();
95 }
96
97};
98
99
101 : QWidget(parent)
102 , d(new Private())
103{
104 setObjectName("KisToolOptionsPopup");
105
106 KConfigGroup group( KSharedConfig::openConfig(), "GUI");
107 setFont(KisUiFont::dockFont());
108
109 d->ignoreHideEvents = false;
110
111 d->housekeeperLayout = new QGridLayout(this);
112 d->housekeeperLayout->setContentsMargins(4,4,4,0);
113 d->housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
114 d->hiderWidget = new QWidget(this);
115 d->hiderWidget->setVisible(false);
116}
117
118
123
125{
126 d->recreateLayout(optionWidgetList);
127}
128
129void KisToolOptionsPopup::contextMenuEvent(QContextMenuEvent *e) {
130
131 Q_UNUSED(e);
132}
133
134void KisToolOptionsPopup::hideEvent(QHideEvent *event)
135{
136 if (d->ignoreHideEvents) {
137 return;
138 }
139 QWidget::hideEvent(event);
140}
141
143{
144}
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)