Changeset View
Changeset View
Standalone View
Standalone View
src/decorationbutton.cpp
Show All 18 Lines | |||||
19 | */ | 19 | */ | ||
20 | #include "decorationbutton.h" | 20 | #include "decorationbutton.h" | ||
21 | #include "decorationbutton_p.h" | 21 | #include "decorationbutton_p.h" | ||
22 | #include "decoration.h" | 22 | #include "decoration.h" | ||
23 | #include "decoration_p.h" | 23 | #include "decoration_p.h" | ||
24 | #include "decoratedclient.h" | 24 | #include "decoratedclient.h" | ||
25 | #include "decorationsettings.h" | 25 | #include "decorationsettings.h" | ||
26 | 26 | | |||
27 | #include <KLocalizedString> | ||||
28 | | ||||
29 | #include <QDebug> | ||||
27 | #include <QElapsedTimer> | 30 | #include <QElapsedTimer> | ||
28 | #include <QHoverEvent> | 31 | #include <QHoverEvent> | ||
29 | #include <QGuiApplication> | 32 | #include <QGuiApplication> | ||
30 | #include <QStyleHints> | 33 | #include <QStyleHints> | ||
31 | #include <QTimer> | 34 | #include <QTimer> | ||
32 | 35 | | |||
33 | namespace KDecoration2 | 36 | namespace KDecoration2 | ||
34 | { | 37 | { | ||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | |||||
279 | 282 | | |||
280 | void DecorationButton::Private::stopPressAndHold() | 283 | void DecorationButton::Private::stopPressAndHold() | ||
281 | { | 284 | { | ||
282 | if (!m_pressAndHoldTimer.isNull()) { | 285 | if (!m_pressAndHoldTimer.isNull()) { | ||
283 | m_pressAndHoldTimer->stop(); | 286 | m_pressAndHoldTimer->stop(); | ||
284 | } | 287 | } | ||
285 | } | 288 | } | ||
286 | 289 | | |||
290 | QString DecorationButton::Private::typeToString(DecorationButtonType type) | ||||
291 | { | ||||
292 | switch (type) { | ||||
cfeck: empty line | |||||
293 | case DecorationButtonType::Menu: | ||||
294 | return i18n("Menu"); | ||||
295 | case DecorationButtonType::ApplicationMenu: | ||||
296 | return i18n("Application menu"); | ||||
297 | case DecorationButtonType::OnAllDesktops: | ||||
298 | if ( this->q->isChecked() ) | ||||
299 | return i18n("On one desktop"); | ||||
300 | else | ||||
301 | return i18n("On all desktops"); | ||||
302 | case DecorationButtonType::Minimize: | ||||
303 | return i18n("Minimize"); | ||||
304 | case DecorationButtonType::Maximize: | ||||
305 | if ( this->q->isChecked() ) | ||||
306 | return i18n("Restore"); | ||||
307 | else | ||||
308 | return i18n("Maximize"); | ||||
309 | case DecorationButtonType::Close: | ||||
310 | return i18n("Close"); | ||||
311 | case DecorationButtonType::ContextHelp: | ||||
312 | return i18n("Context help"); | ||||
313 | case DecorationButtonType::Shade: | ||||
314 | if ( this->q->isChecked() ) | ||||
315 | return i18n("Unshade"); | ||||
316 | else | ||||
317 | return i18n("Shade"); | ||||
318 | case DecorationButtonType::KeepBelow: | ||||
319 | if ( this->q->isChecked() ) | ||||
320 | return i18n("Don't keep below"); | ||||
321 | else | ||||
322 | return i18n("Keep below"); | ||||
323 | case DecorationButtonType::KeepAbove: | ||||
324 | if ( this->q->isChecked() ) | ||||
325 | return i18n("Don't keep above"); | ||||
326 | else | ||||
327 | return i18n("Keep above"); | ||||
328 | default: | ||||
329 | return QString(); | ||||
330 | } | ||||
331 | } | ||||
332 | | ||||
287 | DecorationButton::DecorationButton(DecorationButtonType type, const QPointer<Decoration> &decoration, QObject *parent) | 333 | DecorationButton::DecorationButton(DecorationButtonType type, const QPointer<Decoration> &decoration, QObject *parent) | ||
288 | : QObject(parent) | 334 | : QObject(parent) | ||
289 | , d(new Private(type, decoration, this)) | 335 | , d(new Private(type, decoration, this)) | ||
290 | { | 336 | { | ||
291 | decoration->d->addButton(this); | 337 | decoration->d->addButton(this); | ||
292 | connect(this, &DecorationButton::geometryChanged, | 338 | connect(this, &DecorationButton::geometryChanged, | ||
293 | this, static_cast<void (DecorationButton::*)(const QRectF&)>(&DecorationButton::update)); | 339 | this, static_cast<void (DecorationButton::*)(const QRectF&)>(&DecorationButton::update)); | ||
294 | auto updateSlot = static_cast<void (DecorationButton::*)()>(&DecorationButton::update); | 340 | auto updateSlot = static_cast<void (DecorationButton::*)()>(&DecorationButton::update); | ||
295 | connect(this, &DecorationButton::hoveredChanged, this, updateSlot); | 341 | connect(this, &DecorationButton::hoveredChanged, this, updateSlot); | ||
342 | connect(this, &DecorationButton::hoveredChanged, this, | ||||
343 | [this](bool hovered) { | ||||
344 | if (hovered) { | ||||
345 | //TODO: show tooltip if hovered and hide if not | ||||
346 | const QString type = this->d->typeToString(this->type()); | ||||
347 | this->decoration()->requestShowToolTip(type); | ||||
348 | } else { | ||||
349 | this->decoration()->requestHideToolTip(); | ||||
350 | } | ||||
351 | } | ||||
352 | ); | ||||
296 | connect(this, &DecorationButton::pressedChanged, this, updateSlot); | 353 | connect(this, &DecorationButton::pressedChanged, this, updateSlot); | ||
297 | connect(this, &DecorationButton::checkedChanged, this, updateSlot); | 354 | connect(this, &DecorationButton::checkedChanged, this, updateSlot); | ||
298 | connect(this, &DecorationButton::enabledChanged, this, updateSlot); | 355 | connect(this, &DecorationButton::enabledChanged, this, updateSlot); | ||
299 | connect(this, &DecorationButton::visibilityChanged, this, updateSlot); | 356 | connect(this, &DecorationButton::visibilityChanged, this, updateSlot); | ||
300 | connect(this, &DecorationButton::hoveredChanged, this, | 357 | connect(this, &DecorationButton::hoveredChanged, this, | ||
301 | [this](bool hovered) { | 358 | [this](bool hovered) { | ||
302 | if (hovered) { | 359 | if (hovered) { | ||
303 | emit pointerEntered(); | 360 | emit pointerEntered(); | ||
▲ Show 20 Lines • Show All 196 Lines • Show Last 20 Lines |
empty line