• 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
KoAspectButton.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  * SPDX-FileCopyrightText: 2005-2007 Thomas Zander <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #include "KoAspectButton.h"
7 
8 #include <QPixmap>
9 #include <QPainter>
10 #include <QMouseEvent>
11 
12 namespace {
13  /* XPM -- copyright The Gimp */
14  const char * const _chain_broken_24[] = {
15  /* columns rows colors chars-per-pixel */
16  "9 24 10 1",
17  " c black",
18  ". c #020204",
19  "X c #5A5A5C",
20  "o c gray43",
21  "O c #8F8F91",
22  "+ c #9A9A98",
23  "@ c #B5B5B6",
24  "# c #D0D0D1",
25  "$ c #E8E8E9",
26  "% c None",
27  /* pixels */
28  "%%.....%%",
29  "%.o##@X.%",
30  "%.+...$.%",
31  "%.#.%.#.%",
32  "%.#.%.#.%",
33  "%[email protected]%.#.%",
34  "%.+...#.%",
35  "%.O.o.O.%",
36  "%%[email protected]%%",
37  "%%%.#.%%%",
38  "%%%%%%%%%",
39  "%%%%%%%%%",
40  "%%%%%%%%%",
41  "%%%%%%%%%",
42  "%%%.#.%%%",
43  "%%..#..%%",
44  "%[email protected]%",
45  "%[email protected]@.%",
46  "%[email protected]%.$.%",
47  "%[email protected]%.$.%",
48  "%[email protected]%.$.%",
49  "%.#...$.%",
50  "%.o$#[email protected]%",
51  "%%.....%%"
52  };
53 
54  /* XPM -- copyright The Gimp */
55  const char * const _chain_24[] = {
56  /* columns rows colors chars-per-pixel */
57  "9 24 10 1",
58  " c black",
59  ". c #020204",
60  "X c #5A5A5C",
61  "o c gray43",
62  "O c #8F8F91",
63  "+ c #9A9A98",
64  "@ c #B5B5B6",
65  "# c #D0D0D1",
66  "$ c #E8E8E9",
67  "% c None",
68  /* pixels */
69  "%%%%%%%%%",
70  "%%%%%%%%%",
71  "%%.....%%",
72  "%.o##@X.%",
73  "%.+...$.%",
74  "%.#.%.#.%",
75  "%.#.%.#.%",
76  "%[email protected]%.#.%",
77  "%.+...#.%",
78  "%.O.o.O.%",
79  "%%[email protected]%%",
80  "%%%.#.%%%",
81  "%%%.#.%%%",
82  "%%..#..%%",
83  "%[email protected]%",
84  "%[email protected]@.%",
85  "%[email protected]%.$.%",
86  "%[email protected]%.$.%",
87  "%[email protected]%.$.%",
88  "%.#...$.%",
89  "%.o$#[email protected]%",
90  "%%.....%%",
91  "%%%%%%%%%",
92  "%%%%%%%%%"
93  };
94 }
95 
96 class Q_DECL_HIDDEN KoAspectButton::Private
97 {
98 public:
99  Private()
100  : chain(_chain_24),
101  brokenChain(_chain_broken_24),
102  keepAspect(true)
103  {
104  }
105  const QPixmap chain, brokenChain;
106  bool keepAspect;
107 };
108 
109 KoAspectButton::KoAspectButton(QWidget *parent)
110  : QAbstractButton(parent),
111  d( new Private() )
112 {
113  //setPixmap(d->chain);
114  //setTextInteractionFlags(Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse);
115  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
116 }
117 
118 KoAspectButton::~KoAspectButton()
119 {
120  delete d;
121 }
122 
123 void KoAspectButton::mouseReleaseEvent (QMouseEvent *ev) {
124  if(! isEnabled() || ev->button() != Qt::LeftButton)
125  return;
126  setKeepAspectRatio(!d->keepAspect);
127 }
128 
129 void KoAspectButton::setKeepAspectRatio(bool on) {
130  if(d->keepAspect == on)
131  return;
132  d->keepAspect = on;
133  update();
134  emit keepAspectRatioChanged(d->keepAspect);
135 }
136 
137 void KoAspectButton::paintEvent (QPaintEvent *) {
138  QPainter painter(this);
139  painter.drawPixmap(0, (height() - 24) / 2, 9, 24, d->keepAspect ? d->chain : d->brokenChain, 0, 0, 9, 24);
140  painter.end();
141 }
142 
143 QSize KoAspectButton::sizeHint () const {
144  return QSize(9, 24);
145 }
146 
147 void KoAspectButton::keyReleaseEvent (QKeyEvent *e) {
148  if(e->text() == " ") {
149  setKeepAspectRatio(! d->keepAspect);
150  e->accept();
151  }
152 }
153 
154 bool KoAspectButton::keepAspectRatio() const
155 {
156  return d->keepAspect;
157 }
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
QMouseEvent::button
Qt::MouseButton button() const
QWidget
QSize
QPainter
QMouseEvent
QKeyEvent::text
QString text() const
QPixmap
KoAspectButton.h
QPaintEvent
QWidget::sizeHint
sizeHint
QAbstractButton
Private
QKeyEvent
QEvent::accept
void accept()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 11:48:22 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