• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • krita API Reference
  • KDE Home
  • Contact Us
 

KritaWidgets

  • sources
  • kfour-appscomplete
  • krita
  • libs
  • widgets
KoToolDocker.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  *
3  * SPDX-FileCopyrightText: 2010-2011 C. Boemann <[email protected]>
4  * SPDX-FileCopyrightText: 2005-2006 Boudewijn Rempt <[email protected]>
5  * SPDX-FileCopyrightText: 2006 Thomas Zander <[email protected]>
6  *
7  * SPDX-License-Identifier: LGPL-2.0-or-later
8  */
9 #include "KoToolDocker.h"
10 
11 #include <klocalizedstring.h>
12 
13 #include <QApplication>
14 #include <QGridLayout>
15 #include <QScrollArea>
16 #include <QScroller>
17 #include <QLabel>
18 
19 class Q_DECL_HIDDEN KoToolDocker::Private
20 {
21 public:
22  Private(KoToolDocker *dock)
23  : q(dock)
24  {
25  }
26 
27  QList<QPointer<QWidget> > currentWidgetList;
28  QSet<QWidget *> currentAuxWidgets;
29  QScrollArea *scrollArea;
30  QWidget *hiderWidget; // non current widgets are hidden by being children of this
31  QWidget *housekeeperWidget;
32  QGridLayout *housekeeperLayout;
33  KoToolDocker *q;
34  Qt::DockWidgetArea dockingArea;
35 
36  void resetWidgets()
37  {
38  currentWidgetList.clear();
39  qDeleteAll(currentAuxWidgets);
40  currentAuxWidgets.clear();
41  }
42 
43  void recreateLayout(const QList<QPointer<QWidget> > &optionWidgetList)
44  {
45  Q_FOREACH (QPointer<QWidget> widget, currentWidgetList) {
46  if (!widget.isNull() && widget && hiderWidget) {
47  widget->setParent(hiderWidget);
48  }
49  }
50  qDeleteAll(currentAuxWidgets);
51  currentAuxWidgets.clear();
52 
53  currentWidgetList = optionWidgetList;
54 
55  // need to unstretch row that have previously been stretched
56  housekeeperLayout->setRowStretch(housekeeperLayout->rowCount()-1, 0);
57 
58  int cnt = 0;
59  QFrame *s;
60  QLabel *l;
61  switch(dockingArea) {
62  case Qt::TopDockWidgetArea:
63  case Qt::BottomDockWidgetArea:
64  housekeeperLayout->setHorizontalSpacing(2);
65  housekeeperLayout->setVerticalSpacing(0);
66  Q_FOREACH (QPointer<QWidget> widget, currentWidgetList) {
67  if (widget.isNull() || widget->objectName().isEmpty()) {
68  continue;
69  }
70  if (!widget->windowTitle().isEmpty()) {
71  housekeeperLayout->addWidget(l = new QLabel(widget->windowTitle()), 0, 2*cnt);
72  currentAuxWidgets.insert(l);
73  }
74  housekeeperLayout->addWidget(widget, 1, 2*cnt);
75  widget->show();
76  if (widget != currentWidgetList.last()) {
77  housekeeperLayout->addWidget(s = new QFrame(), 0, 2*cnt+1, 2, 1);
78  s->setFrameShape(QFrame::VLine);
79  currentAuxWidgets.insert(s);
80  }
81  cnt++;
82  }
83  break;
84  case Qt::NoDockWidgetArea:
85  case Qt::LeftDockWidgetArea:
86  case Qt::RightDockWidgetArea: {
87  housekeeperLayout->setHorizontalSpacing(0);
88  housekeeperLayout->setVerticalSpacing(2);
89  int specialCount = 0;
90  Q_FOREACH (QPointer<QWidget> widget, currentWidgetList) {
91  if (widget.isNull() || widget->objectName().isEmpty()) {
92  continue;
93  }
94  if (!widget->windowTitle().isEmpty()) {
95  housekeeperLayout->addWidget(l = new QLabel(widget->windowTitle()), cnt++, 0);
96  currentAuxWidgets.insert(l);
97  }
98  housekeeperLayout->addWidget(widget, cnt++, 0);
99  QLayout *subLayout = widget->layout();
100  if (subLayout) {
101  for (int i = 0; i < subLayout->count(); ++i) {
102  QWidget *spacerWidget = subLayout->itemAt(i)->widget();
103  if (spacerWidget && spacerWidget->objectName().contains("SpecialSpacer")) {
104  specialCount++;
105  }
106  }
107  }
108  widget->show();
109  if (widget != currentWidgetList.last()) {
110  housekeeperLayout->addWidget(s = new QFrame(), cnt++, 0);
111  s->setFrameShape(QFrame::HLine);
112  currentAuxWidgets.insert(s);
113  }
114  }
115  if (specialCount == currentWidgetList.count() || qApp->applicationName().contains("krita")) {
116  housekeeperLayout->setRowStretch(cnt, 10000);
117  }
118  break;
119  }
120  default:
121  break;
122  }
123 
124  housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
125  housekeeperLayout->invalidate();
126  }
127 
128  void locationChanged(Qt::DockWidgetArea area)
129  {
130  dockingArea = area;
131  recreateLayout(currentWidgetList);
132  }
133 
134 };
135 
136 KoToolDocker::KoToolDocker(QWidget *parent)
137  : QDockWidget(i18n("Tool Options"), parent),
138  d(new Private(this))
139 {
140  connect(this, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(locationChanged(Qt::DockWidgetArea)));
141 
142  d->housekeeperWidget = new QWidget();
143  d->housekeeperLayout = new QGridLayout(d->housekeeperWidget);
144  d->housekeeperLayout->setContentsMargins(4,4,4,0);
145  d->housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
146 
147  d->hiderWidget = new QWidget(d->housekeeperWidget);
148  d->hiderWidget->setVisible(false);
149 
150  d->scrollArea = new QScrollArea();
151  d->scrollArea->setWidget(d->housekeeperWidget);
152  d->scrollArea->setFrameShape(QFrame::NoFrame);
153  d->scrollArea->setWidgetResizable(true);
154  d->scrollArea->setFocusPolicy(Qt::NoFocus);
155 
156  QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(d->scrollArea);
157  if( scroller ) {
158  connect(scroller, SIGNAL(stateChanged(QScroller::State)), this, SLOT(slotScrollerStateChange(QScroller::State)));
159  }
160 
161  setWidget(d->scrollArea);
162 }
163 
164 KoToolDocker::~KoToolDocker()
165 {
166  delete d;
167 }
168 
169 bool KoToolDocker::hasOptionWidget()
170 {
171  return !d->currentWidgetList.isEmpty();
172 }
173 
174 void KoToolDocker::setOptionWidgets(const QList<QPointer<QWidget> > &optionWidgetList)
175 {
176  d->recreateLayout(optionWidgetList);
177 }
178 
179 void KoToolDocker::slotScrollerStateChange(QScroller::State state)
180 {
181  KisKineticScroller::updateCursor(d->scrollArea, state);
182 }
183 
184 void KoToolDocker::resetWidgets()
185 {
186  d->resetWidgets();
187 }
188 
189 
190 void KoToolDocker::setCanvas(KoCanvasBase *canvas)
191 {
192  setEnabled(canvas != 0);
193 }
194 
195 void KoToolDocker::unsetCanvas()
196 {
197  setEnabled(false);
198 }
199 
200 //have to include this because of Q_PRIVATE_SLOT
201 #include <moc_KoToolDocker.cpp>
QPointer< QWidget >
QLayout::itemAt
virtual QLayoutItem * itemAt(int index) const=0
QSet< QWidget * >
QLayout::count
virtual int count() const=0
QGridLayout
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
QFrame
QList::count
int count(const T &value) const
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QScrollArea::QScrollArea
QScrollArea(QWidget *parent)
KoToolDocker.h
QWidget
QGridLayout::setHorizontalSpacing
void setHorizontalSpacing(int spacing)
QFrame::setFrameShape
void setFrameShape(Shape)
QList
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLayoutItem::widget
virtual QWidget * widget()
QLayout
QLabel
QGridLayout::setRowStretch
void setRowStretch(int row, int stretch)
QGridLayout::invalidate
virtual void invalidate()
QPointer::isNull
bool isNull() const
QDockWidget
QScrollArea
QGridLayout::rowCount
int rowCount() const
QGridLayout::setVerticalSpacing
void setVerticalSpacing(int spacing)
QList::last
T & last()
QLayout::setSizeConstraint
void setSizeConstraint(SizeConstraint)
QSet::clear
void clear()
QObject::objectName
objectName
QList::clear
void clear()
QSet::insert
const_iterator insert(const T &value)
Private
KoToolBoxScrollArea::slotScrollerStateChange
void slotScrollerStateChange(QScroller::State state)
Definition: KoToolBoxScrollArea_p.h:90
QScrollArea::setWidget
void setWidget(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 11:48:23 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KritaWidgets

Skip menu "KritaWidgets"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

krita API Reference

Skip menu "krita API Reference"
  • libs
  •   KritaBasicFlakes
  •   brush
  •   KritaUndo2
  •   KritaFlake
  •   image
  •   KritaPlugin
  •   Krita
  •   KritaPigment
  •   KritaResources
  •   KritaStore
  •   ui
  •   KritaWidgets
  •   KritaWidgetUtils
  • plugins
  •   Assitants
  •   Extensions
  •   Filters
  •   Generators
  •   Formats
  •           src
  •   PaintOps
  •     libpaintop

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal