Krita Source Code Documentation
Loading...
Searching...
No Matches
KoZoomInput Class Reference

#include <KoZoomInput.h>

+ Inheritance diagram for KoZoomInput:

Classes

class  Private
 

Signals

void explicitZoomLevelRequested (const QString &level)
 
void zoomLevelChanged (const QString &level)
 
void zoomLevelChangedIndex (int index)
 

Public Member Functions

bool eventFilter (QObject *watched, QEvent *event) override
 
bool isFlat () const
 
 KoZoomInput (QWidget *parent=0)
 
void setCurrentZoomLevel (const QString &level)
 
void setCurrentZoomLevel (int index)
 
void setCurrentZoomLevel (int index, const QString &activeText)
 
void setFlat (bool flat)
 
void setZoomLevels (const QStringList &levels)
 
 ~KoZoomInput () override
 

Protected Member Functions

void enterEvent (QEnterEvent *e) override
 
void keyPressEvent (QKeyEvent *event) override
 
void leaveEvent (QEvent *event) override
 

Private Attributes

Private *const d
 

Detailed Description

Definition at line 11 of file KoZoomInput.h.

Constructor & Destructor Documentation

◆ KoZoomInput()

KoZoomInput::KoZoomInput ( QWidget * parent = 0)
explicit

Definition at line 32 of file KoZoomInput.cpp.

33 : QStackedWidget(parent), d(new Private)
34{
35#ifdef Q_OS_MACOS
36 setAttribute(Qt::WA_MacMiniSize, true);
37#endif
38
39 QWidget* first = new QWidget(this);
40 QHBoxLayout* layout = new QHBoxLayout(first);
41 layout->setSpacing(0);
42 layout->setContentsMargins(0, 0, 0, 0);
43 d->label = new QLabel(first);
44 d->label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
45 layout->addWidget(d->label, 10);
46 QLabel* icon = new QLabel(first);
47 QStyleOption option;
48 option.state = QStyle::State_Enabled;
49 QPixmap pixmap(16, 16);
50 pixmap.fill(QColor(255, 255, 255, 0));
51 QPainter painter(&pixmap);
52 painter.translate(8, 8);
53 style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &option, &painter);
54 icon->setPixmap(pixmap);
55 layout->addWidget(icon);
56 addWidget(first);
57 d->combo = new QComboBox(this);
58 d->combo->setMaxVisibleItems(15);
59 d->combo->setEditable(true);
60 d->combo->installEventFilter(this);
61 addWidget(d->combo);
62 d->inside = false;
63 d->isFlat = true;
64
65 connect(d->combo, SIGNAL(textActivated(QString)), this, SIGNAL(zoomLevelChanged(QString)));
66 connect(d->combo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(zoomLevelChangedIndex(int)));
67}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
Private *const d
Definition KoZoomInput.h:44
void zoomLevelChangedIndex(int index)
void zoomLevelChanged(const QString &level)

References KoZoomInput::Private::combo, connect(), d, KoZoomInput::Private::inside, KoZoomInput::Private::isFlat, KoZoomInput::Private::label, zoomLevelChanged(), and zoomLevelChangedIndex().

◆ ~KoZoomInput()

KoZoomInput::~KoZoomInput ( )
override

Definition at line 69 of file KoZoomInput.cpp.

70{
71 delete d;
72}

References d.

Member Function Documentation

◆ enterEvent()

void KoZoomInput::enterEvent ( QEnterEvent * e)
overrideprotected

Definition at line 76 of file KoZoomInput.cpp.

78{
79 Q_UNUSED(event);
80
81 d->inside = true;
82 if (!isFlat()) {
83 return;
84 }
85
86 if (d->combo->view())
87 {
88 d->combo->view()->removeEventFilter(this);
89 }
90
91 setCurrentIndex(1);
92}
bool isFlat() const

◆ eventFilter()

bool KoZoomInput::eventFilter ( QObject * watched,
QEvent * event )
override

Definition at line 177 of file KoZoomInput.cpp.

178{
179 if(watched == d->combo->view() && event->type() == QEvent::Hide)
180 {
181 focusNextChild();
182 setCurrentIndex(0);
183 }
184 else if (watched == d->combo && event->type() == QEvent::FocusOut &&
185 (d->combo->view() && !d->combo->view()->hasFocus()) && !d->inside)
186 {
187 setCurrentIndex(0);
188 }
189 return false;
190}

References KoZoomInput::Private::combo, d, and KoZoomInput::Private::inside.

◆ explicitZoomLevelRequested

void KoZoomInput::explicitZoomLevelRequested ( const QString & level)
signal

◆ isFlat()

bool KoZoomInput::isFlat ( ) const

Definition at line 122 of file KoZoomInput.cpp.

123{
124 return d->isFlat;
125}

References d, and KoZoomInput::Private::isFlat.

◆ keyPressEvent()

void KoZoomInput::keyPressEvent ( QKeyEvent * event)
overrideprotected

Definition at line 113 of file KoZoomInput.cpp.

114{
115 if (event->key() == Qt::Key_Return ||
116 event->key() == Qt::Key_Enter)
117 {
118 focusNextChild();
119 }
120}

◆ leaveEvent()

void KoZoomInput::leaveEvent ( QEvent * event)
overrideprotected

Definition at line 94 of file KoZoomInput.cpp.

95{
96 Q_UNUSED(event);
97
98 d->inside = false;
99 if (!isFlat()) {
100 return;
101 }
102
103 if(d->combo->view() && d->combo->view()->isVisible())
104 {
105 d->combo->view()->installEventFilter(this);
106 return;
107 }
108
109 if(!d->combo->hasFocus())
110 setCurrentIndex(0);
111}

References KoZoomInput::Private::combo, d, KoZoomInput::Private::inside, and isFlat().

◆ setCurrentZoomLevel() [1/3]

void KoZoomInput::setCurrentZoomLevel ( const QString & level)

Definition at line 171 of file KoZoomInput.cpp.

172{
173 d->combo->setCurrentIndex(d->combo->findText(level));
174 d->label->setText(level);
175}

References KoZoomInput::Private::combo, d, and KoZoomInput::Private::label.

◆ setCurrentZoomLevel() [2/3]

void KoZoomInput::setCurrentZoomLevel ( int index)

Definition at line 160 of file KoZoomInput.cpp.

161{
162 setCurrentZoomLevel(index, d->combo->itemText(index));
163}
void setCurrentZoomLevel(const QString &level)

References KoZoomInput::Private::combo, d, and setCurrentZoomLevel().

◆ setCurrentZoomLevel() [3/3]

void KoZoomInput::setCurrentZoomLevel ( int index,
const QString & activeText )

Definition at line 165 of file KoZoomInput.cpp.

166{
167 d->combo->setCurrentIndex(index);
168 d->label->setText(activeText);
169}

References KoZoomInput::Private::combo, d, and KoZoomInput::Private::label.

◆ setFlat()

void KoZoomInput::setFlat ( bool flat)

Definition at line 127 of file KoZoomInput.cpp.

128{
129 if (flat == d->isFlat) {
130 return;
131 }
132
133 d->isFlat = flat;
134
135 if (flat) {
136 d->combo->installEventFilter(this);
137 if (d->inside) {
138 enterEvent(nullptr);
139 } else {
140 leaveEvent(nullptr);
141 }
142 d->combo->setEditable(true);
143 } else {
144 d->combo->removeEventFilter(this);
145 if (d->combo->view()) {
146 d->combo->view()->removeEventFilter(this);
147 }
148 d->combo->setCurrentIndex(d->combo->findText(d->label->text()));
149 d->combo->setEditable(false);
150 setCurrentIndex(1);
151 }
152}
void enterEvent(QEnterEvent *e) override
void leaveEvent(QEvent *event) override

References KoZoomInput::Private::combo, d, enterEvent(), KoZoomInput::Private::inside, KoZoomInput::Private::isFlat, KoZoomInput::Private::label, and leaveEvent().

◆ setZoomLevels()

void KoZoomInput::setZoomLevels ( const QStringList & levels)

Definition at line 154 of file KoZoomInput.cpp.

155{
156 d->combo->clear();
157 d->combo->addItems(levels);
158}

References KoZoomInput::Private::combo, and d.

◆ zoomLevelChanged

void KoZoomInput::zoomLevelChanged ( const QString & level)
signal

◆ zoomLevelChangedIndex

void KoZoomInput::zoomLevelChangedIndex ( int index)
signal

Member Data Documentation

◆ d

Private* const KoZoomInput::d
private

Definition at line 44 of file KoZoomInput.h.


The documentation for this class was generated from the following files: