diff --git a/src/colors/kcolorutils.h b/src/colors/kcolorutils.h index 5274418..0785518 100644 --- a/src/colors/kcolorutils.h +++ b/src/colors/kcolorutils.h @@ -1,160 +1,160 @@ /* This file is part of the KDE project * Copyright (C) 2007 Matthew Woehlke * Copyright (C) 2007 Thomas Zander * Copyright (C) 2007 Zack Rusin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORUTILS_H #define KCOLORUTILS_H #include #include class QColor; /** * A set of methods used to work with colors. */ namespace KColorUtils { /** * Calculate the luma of a color. Luma is weighted sum of gamma-adjusted * R'G'B' components of a color. The result is similar to qGray. The range * is from 0.0 (black) to 1.0 (white). * * KColorUtils::darken(), KColorUtils::lighten() and KColorUtils::shade() * operate on the luma of a color. * * @see http://en.wikipedia.org/wiki/Luma_(video) */ KGUIADDONS_EXPORT qreal luma(const QColor &); /** * Calculate hue, chroma and luma of a color in one call. * @since 5.0 */ -KGUIADDONS_EXPORT void getHcy(const QColor &, qreal *hue, qreal *chroma, qreal *luma, qreal *alpha = 0); +KGUIADDONS_EXPORT void getHcy(const QColor &, qreal *hue, qreal *chroma, qreal *luma, qreal *alpha = nullptr); /** * Calculate the contrast ratio between two colors, according to the * W3C/WCAG2.0 algorithm, (Lmax + 0.05)/(Lmin + 0.05), where Lmax and Lmin * are the luma values of the lighter color and the darker color, * respectively. * * A contrast ration of 5:1 (result == 5.0) is the minimum for "normal" * text to be considered readable (large text can go as low as 3:1). The * ratio ranges from 1:1 (result == 1.0) to 21:1 (result == 21.0). * * @see KColorUtils::luma */ KGUIADDONS_EXPORT qreal contrastRatio(const QColor &, const QColor &); /** * Adjust the luma of a color by changing its distance from white. * * @li amount == 1.0 gives white * @li amount == 0.5 results in a color whose luma is halfway between 1.0 * and that of the original color * @li amount == 0.0 gives the original color * @li amount == -1.0 gives a color that is 'twice as far from white' as * the original color, that is luma(result) == 1.0 - 2*(1.0 - luma(color)) * * @param amount factor by which to adjust the luma component of the color * @param chromaInverseGain (optional) factor by which to adjust the chroma * component of the color; 1.0 means no change, 0.0 maximizes chroma * @see KColorUtils::shade */ KGUIADDONS_EXPORT QColor lighten(const QColor &, qreal amount = 0.5, qreal chromaInverseGain = 1.0); /** * Adjust the luma of a color by changing its distance from black. * * @li amount == 1.0 gives black * @li amount == 0.5 results in a color whose luma is halfway between 0.0 * and that of the original color * @li amount == 0.0 gives the original color * @li amount == -1.0 gives a color that is 'twice as far from black' as * the original color, that is luma(result) == 2*luma(color) * * @param amount factor by which to adjust the luma component of the color * @param chromaGain (optional) factor by which to adjust the chroma * component of the color; 1.0 means no change, 0.0 minimizes chroma * @see KColorUtils::shade */ KGUIADDONS_EXPORT QColor darken(const QColor &, qreal amount = 0.5, qreal chromaGain = 1.0); /** * Adjust the luma and chroma components of a color. The amount is added * to the corresponding component. * * @param lumaAmount amount by which to adjust the luma component of the * color; 0.0 results in no change, -1.0 turns anything black, 1.0 turns * anything white * @param chromaAmount (optional) amount by which to adjust the chroma * component of the color; 0.0 results in no change, -1.0 minimizes chroma, * 1.0 maximizes chroma * @see KColorUtils::luma */ KGUIADDONS_EXPORT QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount = 0.0); /** * Create a new color by tinting one color with another. This function is * meant for creating additional colors withings the same class (background, * foreground) from colors in a different class. Therefore when @p amount * is low, the luma of @p base is mostly preserved, while the hue and * chroma of @p color is mostly inherited. * * @param base color to be tinted * @param color color with which to tint * @param amount how strongly to tint the base; 0.0 gives @p base, * 1.0 gives @p color */ KGUIADDONS_EXPORT QColor tint(const QColor &base, const QColor &color, qreal amount = 0.3); /** * Blend two colors into a new color by linear combination. * @code QColor lighter = KColorUtils::mix(myColor, Qt::white) * @endcode * @param c1 first color. * @param c2 second color. * @param bias weight to be used for the mix. @p bias <= 0 gives @p c1, * @p bias >= 1 gives @p c2. @p bias == 0.5 gives a 50% blend of @p c1 * and @p c2. */ KGUIADDONS_EXPORT QColor mix(const QColor &c1, const QColor &c2, qreal bias = 0.5); /** * Blend two colors into a new color by painting the second color over the * first using the specified composition mode. * @code QColor white(Qt::white); white.setAlphaF(0.5); QColor lighter = KColorUtils::overlayColors(myColor, white); @endcode * @param base the base color (alpha channel is ignored). * @param paint the color to be overlayed onto the base color. * @param comp the CompositionMode used to do the blending. */ KGUIADDONS_EXPORT QColor overlayColors(const QColor &base, const QColor &paint, QPainter::CompositionMode comp = QPainter::CompositionMode_SourceOver); } #endif // KCOLORUTILS_H diff --git a/src/text/kdatevalidator.cpp b/src/text/kdatevalidator.cpp index b45dd4d..16365d7 100644 --- a/src/text/kdatevalidator.cpp +++ b/src/text/kdatevalidator.cpp @@ -1,74 +1,74 @@ /* -*- C++ -*- This file is part of the KDE libraries Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) (C) 1998-2001 Mirko Boehm (mirko@kde.org) (C) 2007 John Layt This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kdatevalidator.h" #include #include class KDateValidator::KDateValidatorPrivate { public: KDateValidatorPrivate(KDateValidator *q): q(q) { } ~KDateValidatorPrivate() { } KDateValidator *q; }; -KDateValidator::KDateValidator(QObject *parent) : QValidator(parent), d(0) +KDateValidator::KDateValidator(QObject *parent) : QValidator(parent), d(nullptr) { Q_UNUSED(d); } QValidator::State KDateValidator::validate(QString &text, int &unused) const { Q_UNUSED(unused); QDate temp; // ----- everything is tested in date(): return date(text, temp); } QValidator::State KDateValidator::date(const QString &text, QDate &d) const { QLocale::FormatType formats[] = { QLocale::LongFormat, QLocale::ShortFormat, QLocale::NarrowFormat }; QLocale locale; for (int i = 0; i < 3; i++) { QDate tmp = locale.toDate(text, formats[i]); if (tmp.isValid()) { d = tmp; return Acceptable; } } return QValidator::Intermediate; } void KDateValidator::fixup(QString &) const { } diff --git a/src/text/kdatevalidator.h b/src/text/kdatevalidator.h index 6c6ef3a..0b8cafd 100644 --- a/src/text/kdatevalidator.h +++ b/src/text/kdatevalidator.h @@ -1,45 +1,45 @@ /* -*- C++ -*- This file is part of the KDE libraries Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) (C) 1998-2001 Mirko Boehm (mirko@kde.org) (C) 2007 John Layt This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDATEVALIDATOR_H #define KDATEVALIDATOR_H #include #include /** * Validates user-entered dates. */ class KGUIADDONS_EXPORT KDateValidator : public QValidator { public: - explicit KDateValidator(QObject *parent = 0); + explicit KDateValidator(QObject *parent = nullptr); State validate(QString &text, int &e) const Q_DECL_OVERRIDE; void fixup(QString &input) const Q_DECL_OVERRIDE; State date(const QString &text, QDate &date) const; private: class KDateValidatorPrivate; friend class KDateValidatorPrivate; KDateValidatorPrivate *const d; }; #endif // KDATEVALIDATOR_H diff --git a/src/util/klocalimagecacheimpl.cpp b/src/util/klocalimagecacheimpl.cpp index d34dbe7..c13c9aa 100644 --- a/src/util/klocalimagecacheimpl.cpp +++ b/src/util/klocalimagecacheimpl.cpp @@ -1,163 +1,163 @@ /* * This file is part of the KDE project. * Copyright © 2010 Michael Pyne * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "klocalimagecacheimpl.h" #include #include #include #include #include #include /** * This is a QObject subclass so we can catch the signal that the application is about * to close and properly release any QPixmaps we have cached. */ class KLocalImageCacheImplementationPrivate : public QObject { Q_OBJECT public: - KLocalImageCacheImplementationPrivate(QObject *parent = 0) + KLocalImageCacheImplementationPrivate(QObject *parent = nullptr) : QObject(parent) , timestamp(QDateTime::currentDateTime()) , enablePixmapCaching(true) { QObject::connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(clearPixmaps())); } /** * Inserts a pixmap into the pixmap cache if the pixmap cache is enabled, with * weighting based on image size and bit depth. */ bool insertPixmap(const QString &key, QPixmap *pixmap) { if (enablePixmapCaching && pixmap && !pixmap->isNull()) { // "cost" parameter is based on both image size and depth to make cost // based on size in bytes instead of area on-screen. return pixmapCache.insert(key, pixmap, pixmap->width() * pixmap->height() * pixmap->depth() / 8); } return false; } public Q_SLOTS: void clearPixmaps() { pixmapCache.clear(); } public: QDateTime timestamp; /** * This is used to cache pixmaps as they are inserted, instead of always * converting to image data and storing that in shared memory. */ QCache pixmapCache; bool enablePixmapCaching; }; KLocalImageCacheImplementation::KLocalImageCacheImplementation(unsigned defaultCacheSize) : d(new KLocalImageCacheImplementationPrivate) { // Use at least 16 KiB for the pixmap cache d->pixmapCache.setMaxCost(qMax(defaultCacheSize / 8, (unsigned int) 16384)); } KLocalImageCacheImplementation::~KLocalImageCacheImplementation() { delete d; } void KLocalImageCacheImplementation::updateModifiedTime() { d->timestamp = QDateTime::currentDateTime(); } QByteArray KLocalImageCacheImplementation::serializeImage(const QImage &image) const { QBuffer buffer; buffer.open(QBuffer::WriteOnly); image.save(&buffer, "PNG"); return buffer.buffer(); } bool KLocalImageCacheImplementation::insertLocalPixmap(const QString &key, const QPixmap &pixmap) const { return d->insertPixmap(key, new QPixmap(pixmap)); } bool KLocalImageCacheImplementation::findLocalPixmap(const QString &key, QPixmap *destination) const { if (d->enablePixmapCaching) { QPixmap *cachedPixmap = d->pixmapCache.object(key); if (cachedPixmap) { if (destination) { *destination = *cachedPixmap; } return true; } } return false; } void KLocalImageCacheImplementation::clearLocalCache() { d->pixmapCache.clear(); } QDateTime KLocalImageCacheImplementation::lastModifiedTime() const { return d->timestamp; } bool KLocalImageCacheImplementation::pixmapCaching() const { return d->enablePixmapCaching; } void KLocalImageCacheImplementation::setPixmapCaching(bool enable) { if (enable != d->enablePixmapCaching) { d->enablePixmapCaching = enable; if (!enable) { d->pixmapCache.clear(); } } } int KLocalImageCacheImplementation::pixmapCacheLimit() const { return d->pixmapCache.maxCost(); } void KLocalImageCacheImplementation::setPixmapCacheLimit(int size) { d->pixmapCache.setMaxCost(size); } #include "klocalimagecacheimpl.moc" diff --git a/src/util/kmodifierkeyinfo.h b/src/util/kmodifierkeyinfo.h index e999762..2321149 100644 --- a/src/util/kmodifierkeyinfo.h +++ b/src/util/kmodifierkeyinfo.h @@ -1,189 +1,189 @@ /* Copyright 2009 Michael Leupold This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef KMODIFIERKEYINFO_H #define KMODIFIERKEYINFO_H #include #include class KModifierKeyInfoProvider; /** * Get information about the state of the keyboard's modifier keys. * * This class provides cross-platform information about the state of the * keyboard's modifier keys and the mouse buttons and allows to change the * state as well. * * It recognizes two states a key can be in: *
  • locked: eg. caps-locked (aka toggled)
  • *
  • latched: the key is temporarily locked but will be unlocked upon * the next keypress.
* * An application can either query the states synchronously (@see isKeyLatched, * @see isKeyLocked) or connect to KModifierKeyInfo's signals to be notified about * changes (@see keyLatched, @see keyLocked). */ class KGUIADDONS_EXPORT KModifierKeyInfo : public QObject { Q_OBJECT public: /** * Default constructor */ - KModifierKeyInfo(QObject *parent = 0); + KModifierKeyInfo(QObject *parent = nullptr); /** * Destructor */ virtual ~KModifierKeyInfo(); /** * Check if a key is known by the underlying window system and can be queried. * * @param key The key to check * @return true if the key is available, false if it is unknown */ bool knowsKey(Qt::Key key) const; /** * Get a list of known keys. * * @return A list of known keys of which states will be reported. */ const QList knownKeys() const; /** * Synchronously check if a key is pressed. * * @param key The key to check * @return true if the key is pressed, false if the key is not pressed or unknown. * @see isKeyLatched, @see isKeyLocked, @see keyPressed */ bool isKeyPressed(Qt::Key key) const; /** * Synchronously check if a key is latched. * * @param key The key to check * @return true if the key is latched, false if the key is not latched or unknown. * @see isKeyPressed, @see isKeyLocked, @see keyLatched */ bool isKeyLatched(Qt::Key key) const; /** * Set the latched state of a key. * * @param key The key to latch * @param latched true to latch the key, false to unlatch it. * @return false if the key is unknown. true doesn't guarantee you the * operation worked. */ bool setKeyLatched(Qt::Key key, bool latched); /** * Synchronously check if a key is locked. * * @param key The key to check * @return true if the key is locked, false if the key is not locked or unknown. * @see isKeyPressed, @see isKeyLatched, @see keyLocked */ bool isKeyLocked(Qt::Key key) const; /** * Set the locked state of a key. * * @param key The key to lock * @param latched true to lock the key, false to unlock it. * @return false if the key is unknown. true doesn't guarantee you the * operation worked. */ bool setKeyLocked(Qt::Key key, bool locked); /** * Synchronously check if a mouse button is pressed. * * @param button The mouse button to check * @return true if the mouse button is pressed, false if the mouse button * is not pressed or its state is unknown. */ bool isButtonPressed(Qt::MouseButton button) const; Q_SIGNALS: /** * This signal is emitted whenever the pressed state of a key changes * (key press or key release). * * @param key The key that changed state * @param pressed true if the key is now pressed, false if is released. */ void keyPressed(Qt::Key key, bool pressed); /** * This signal is emitted whenever the latched state of a key changes. * * @param key The key that changed state * @param latched true if the key is now latched, false if it isn't */ void keyLatched(Qt::Key key, bool latched); /** * This signal is emitted whenever the locked state of a key changes. * * @param key The key that changed state * @param locked true if the key is now locked, false if it isn't */ void keyLocked(Qt::Key key, bool locked); /** * This signal is emitted whenever the pressed state of a mouse button * changes (mouse button press or release). * * @param button The mouse button that changed state * @param pressed true if the mouse button is now pressed, false if * is released. */ void buttonPressed(Qt::MouseButton button, bool pressed); /** * This signal is emitted whenever a new modifier is found due to * the keyboard mapping changing. * * @param key The key that was discovered */ void keyAdded(Qt::Key key); /** * This signal is emitted whenever a previously known modifier no * longer exists due to the keyboard mapping changing. * * @param key The key that vanished */ void keyRemoved(Qt::Key key); private: Q_DISABLE_COPY(KModifierKeyInfo) KModifierKeyInfoProvider *const p; // krazy:exclude=dpointer }; #endif diff --git a/src/util/kmodifierkeyinfoprovider_x11.cpp b/src/util/kmodifierkeyinfoprovider_x11.cpp index 9216acf..0d0a289 100644 --- a/src/util/kmodifierkeyinfoprovider_x11.cpp +++ b/src/util/kmodifierkeyinfoprovider_x11.cpp @@ -1,362 +1,362 @@ /* Copyright 2009 Michael Leupold Copyright 2013 Martin Gräßlin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "kmodifierkeyinfo.h" #include "kmodifierkeyinfoprovider_p.h" #include #include #define XK_MISCELLANY #define XK_XKB_KEYS #include #include #include struct ModifierDefinition { ModifierDefinition(Qt::Key _key, unsigned int _mask, const char *_name, KeySym _keysym) { key = _key; mask = _mask; name = _name; keysym = _keysym; } Qt::Key key; unsigned int mask; const char *name; // virtual modifier name KeySym keysym; }; /* * Get the real modifiers related to a virtual modifier. */ unsigned int xkbVirtualModifier(XkbDescPtr xkb, const char *name) { - Q_ASSERT(xkb != 0); + Q_ASSERT(xkb != nullptr); unsigned int mask = 0; bool nameEqual; for (int i = 0; i < XkbNumVirtualMods; ++i) { char *modStr = XGetAtomName(xkb->dpy, xkb->names->vmods[i]); - if (modStr != 0) { + if (modStr != nullptr) { nameEqual = (strcmp(name, modStr) == 0); XFree(modStr); if (nameEqual) { XkbVirtualModsToReal(xkb, 1 << i, &mask); break; } } } return mask; } KModifierKeyInfoProvider::KModifierKeyInfoProvider() - : QObject(0) + : QObject(nullptr) , QAbstractNativeEventFilter() , m_xkbEv(0) , m_xkbAvailable(false) { if (qApp) { if (qApp->platformName() == QStringLiteral("xcb")) { int code, xkberr, maj, min; m_xkbAvailable = XkbQueryExtension(QX11Info::display(), &code, &m_xkbEv, &xkberr, &maj, &min); } } if (m_xkbAvailable) { XkbSelectEvents(QX11Info::display(), XkbUseCoreKbd, XkbStateNotifyMask | XkbMapNotifyMask, XkbStateNotifyMask | XkbMapNotifyMask); unsigned long int stateMask = XkbModifierStateMask | XkbModifierBaseMask | XkbModifierLatchMask | XkbModifierLockMask | XkbPointerButtonMask; XkbSelectEventDetails(QX11Info::display(), XkbUseCoreKbd, XkbStateNotifyMask, stateMask, stateMask); } xkbUpdateModifierMapping(); // add known pointer buttons m_xkbButtons.insert(Qt::LeftButton, Button1Mask); m_xkbButtons.insert(Qt::MidButton, Button2Mask); m_xkbButtons.insert(Qt::RightButton, Button3Mask); m_xkbButtons.insert(Qt::XButton1, Button4Mask); m_xkbButtons.insert(Qt::XButton2, Button5Mask); // get the initial state if (m_xkbAvailable) { XkbStateRec state; XkbGetState(QX11Info::display(), XkbUseCoreKbd, &state); xkbModifierStateChanged(state.mods, state.latched_mods, state.locked_mods); xkbButtonStateChanged(state.ptr_buttons); QCoreApplication::instance()->installNativeEventFilter(this); } } KModifierKeyInfoProvider::~KModifierKeyInfoProvider() { if (m_xkbAvailable) { QCoreApplication::instance()->removeNativeEventFilter(this); } } bool KModifierKeyInfoProvider::setKeyLatched(Qt::Key key, bool latched) { if (!m_xkbModifiers.contains(key)) { return false; } return XkbLatchModifiers(QX11Info::display(), XkbUseCoreKbd, m_xkbModifiers[key], latched ? m_xkbModifiers[key] : 0); } bool KModifierKeyInfoProvider::setKeyLocked(Qt::Key key, bool locked) { if (!m_xkbModifiers.contains(key)) { return false; } return XkbLockModifiers(QX11Info::display(), XkbUseCoreKbd, m_xkbModifiers[key], locked ? m_xkbModifiers[key] : 0); } // HACK: xcb-xkb is not yet a public part of xcb. Because of that we have to include the event structure. namespace { typedef struct _xcb_xkb_map_notify_event_t { uint8_t response_type; uint8_t xkbType; uint16_t sequence; xcb_timestamp_t time; uint8_t deviceID; uint8_t ptrBtnActions; uint16_t changed; xcb_keycode_t minKeyCode; xcb_keycode_t maxKeyCode; uint8_t firstType; uint8_t nTypes; xcb_keycode_t firstKeySym; uint8_t nKeySyms; xcb_keycode_t firstKeyAct; uint8_t nKeyActs; xcb_keycode_t firstKeyBehavior; uint8_t nKeyBehavior; xcb_keycode_t firstKeyExplicit; uint8_t nKeyExplicit; xcb_keycode_t firstModMapKey; uint8_t nModMapKeys; xcb_keycode_t firstVModMapKey; uint8_t nVModMapKeys; uint16_t virtualMods; uint8_t pad0[2]; } _xcb_xkb_map_notify_event_t; typedef struct _xcb_xkb_state_notify_event_t { uint8_t response_type; uint8_t xkbType; uint16_t sequence; xcb_timestamp_t time; uint8_t deviceID; uint8_t mods; uint8_t baseMods; uint8_t latchedMods; uint8_t lockedMods; uint8_t group; int16_t baseGroup; int16_t latchedGroup; uint8_t lockedGroup; uint8_t compatState; uint8_t grabMods; uint8_t compatGrabMods; uint8_t lookupMods; uint8_t compatLoockupMods; uint16_t ptrBtnState; uint16_t changed; xcb_keycode_t keycode; uint8_t eventType; uint8_t requestMajor; uint8_t requestMinor; } _xcb_xkb_state_notify_event_t; typedef union { /* All XKB events share these fields. */ struct { uint8_t response_type; uint8_t xkbType; uint16_t sequence; xcb_timestamp_t time; uint8_t deviceID; } any; _xcb_xkb_map_notify_event_t map_notify; _xcb_xkb_state_notify_event_t state_notify; } _xkb_event; } bool KModifierKeyInfoProvider::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) { Q_UNUSED(result) if (!m_xkbAvailable || eventType != "xcb_generic_event_t") { return false; } xcb_generic_event_t *event = static_cast(message); if ((event->response_type & ~0x80) == m_xkbEv + XkbEventCode) { _xkb_event *kbevt = reinterpret_cast<_xkb_event *>(event); unsigned int stateMask = XkbModifierStateMask | XkbModifierBaseMask | XkbModifierLatchMask | XkbModifierLockMask; if (kbevt->any.xkbType == XkbMapNotify) { xkbUpdateModifierMapping(); } else if (kbevt->any.xkbType == XkbStateNotify) { if (kbevt->state_notify.changed & stateMask) { xkbModifierStateChanged(kbevt->state_notify.mods, kbevt->state_notify.latchedMods, kbevt->state_notify.lockedMods); } else if (kbevt->state_notify.changed & XkbPointerButtonMask) { xkbButtonStateChanged(kbevt->state_notify.ptrBtnState); } } } return false; } void KModifierKeyInfoProvider::xkbModifierStateChanged(unsigned char mods, unsigned char latched_mods, unsigned char locked_mods) { // detect keyboard modifiers ModifierStates oldState; ModifierStates newState; QHash::const_iterator it; QHash::const_iterator end = m_xkbModifiers.constEnd(); for (it = m_xkbModifiers.constBegin(); it != end; ++it) { if (!m_modifierStates.contains(it.key())) { continue; } newState = Nothing; oldState = m_modifierStates[it.key()]; // determine the new state if (mods & it.value()) { newState |= Pressed; } if (latched_mods & it.value()) { newState |= Latched; } if (locked_mods & it.value()) { newState |= Locked; } if (newState != oldState) { m_modifierStates[it.key()] = newState; if ((newState ^ oldState) & Pressed) { emit keyPressed(it.key(), newState & Pressed); } if ((newState ^ oldState) & Latched) { emit keyLatched(it.key(), newState & Latched); } if ((newState ^ oldState) & Locked) { emit keyLocked(it.key(), newState & Locked); } } } } void KModifierKeyInfoProvider::xkbButtonStateChanged(unsigned short ptr_buttons) { // detect mouse button states bool newButtonState; QHash::const_iterator it; QHash::const_iterator end = m_xkbButtons.constEnd(); for (it = m_xkbButtons.constBegin(); it != end; ++it) { newButtonState = (ptr_buttons & it.value()); if (newButtonState != m_buttonStates[it.key()]) { m_buttonStates[it.key()] = newButtonState; emit buttonPressed(it.key(), newButtonState); } } } void KModifierKeyInfoProvider::xkbUpdateModifierMapping() { if (!m_xkbAvailable) { return; } m_xkbModifiers.clear(); QList srcModifiers; - srcModifiers << ModifierDefinition(Qt::Key_Shift, ShiftMask, 0, 0) - << ModifierDefinition(Qt::Key_Control, ControlMask, 0, 0) + srcModifiers << ModifierDefinition(Qt::Key_Shift, ShiftMask, nullptr, 0) + << ModifierDefinition(Qt::Key_Control, ControlMask, nullptr, 0) << ModifierDefinition(Qt::Key_Alt, 0, "Alt", XK_Alt_L) // << { 0, 0, I18N_NOOP("Win"), "superkey", "" } << ModifierDefinition(Qt::Key_Meta, 0, "Meta", XK_Meta_L) << ModifierDefinition(Qt::Key_Super_L, 0, "Super", XK_Super_L) << ModifierDefinition(Qt::Key_Hyper_L, 0, "Hyper", XK_Hyper_L) << ModifierDefinition(Qt::Key_AltGr, 0, "AltGr", 0) << ModifierDefinition(Qt::Key_NumLock, 0, "NumLock", XK_Num_Lock) - << ModifierDefinition(Qt::Key_CapsLock, LockMask, 0, 0) + << ModifierDefinition(Qt::Key_CapsLock, LockMask, nullptr, 0) << ModifierDefinition(Qt::Key_ScrollLock, 0, "ScrollLock", XK_Scroll_Lock); XkbDescPtr xkb = XkbGetKeyboard(QX11Info::display(), XkbAllComponentsMask, XkbUseCoreKbd); QList::const_iterator it; QList::const_iterator end = srcModifiers.constEnd(); for (it = srcModifiers.constBegin(); it != end; ++it) { unsigned int mask = it->mask; - if (mask == 0 && xkb != 0) { + if (mask == 0 && xkb != nullptr) { // try virtual modifier first - if (it->name != 0) { + if (it->name != nullptr) { mask = xkbVirtualModifier(xkb, it->name); } if (mask == 0 && it->keysym != 0) { mask = XkbKeysymToModifiers(QX11Info::display(), it->keysym); } else if (mask == 0) { // special case for AltGr mask = XkbKeysymToModifiers(QX11Info::display(), XK_Mode_switch) | XkbKeysymToModifiers(QX11Info::display(), XK_ISO_Level3_Shift) | XkbKeysymToModifiers(QX11Info::display(), XK_ISO_Level3_Latch) | XkbKeysymToModifiers(QX11Info::display(), XK_ISO_Level3_Lock); } } if (mask != 0) { m_xkbModifiers.insert(it->key, mask); // previously unknown modifier if (!m_modifierStates.contains(it->key)) { m_modifierStates.insert(it->key, Nothing); emit keyAdded(it->key); } } } // remove modifiers which are no longer available QMutableHashIterator i(m_modifierStates); while (i.hasNext()) { i.next(); if (!m_xkbModifiers.contains(i.key())) { Qt::Key key = i.key(); i.remove(); emit keyRemoved(key); } } - if (xkb != 0) { + if (xkb != nullptr) { XkbFreeKeyboard(xkb, 0, true); } } diff --git a/src/util/urlhandler.cpp b/src/util/urlhandler.cpp index 1fd5984..b61199a 100644 --- a/src/util/urlhandler.cpp +++ b/src/util/urlhandler.cpp @@ -1,69 +1,69 @@ /********************************************************************************* * * * Copyright (C) 2013 Aleix Pol Gonzalez * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) version 3, or any * * later version accepted by the membership of KDE e.V. (or its * * successor approved by the membership of KDE e.V.), which shall * * act as a proxy defined in Section 6 of version 3 of the license. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library. If not, see . * * * *********************************************************************************/ #include #include #include #include #include #include #include class UrlHandler : public QObject { Q_OBJECT public: - explicit UrlHandler(QObject *parent = 0) : QObject(parent) {} + explicit UrlHandler(QObject *parent = nullptr) : QObject(parent) {} public Q_SLOTS: void openHelp(const QUrl &url) { QUrl u(url); if (u.path() == QLatin1String("/")) { u.setPath(QCoreApplication::applicationName()); } QString helpcenter = QStandardPaths::findExecutable(QStringLiteral("khelpcenter")); if (helpcenter.isEmpty()) { if (QCoreApplication::organizationDomain() == QLatin1String("kde.org")) { //if khelpcenter is not installed and it's a KDE application, use docs.kde.org const QUrl httpUrl(QStringLiteral("https://docs.kde.org/index.php?branch=stable5&language=")+QLocale().name()+QStringLiteral("&application=") + QCoreApplication::applicationName() + QStringLiteral("&path=") + url.path()); QDesktopServices::openUrl(httpUrl); } else QDesktopServices::openUrl(u); } else { QProcess::startDetached(helpcenter, QStringList(u.toString())); } } }; Q_GLOBAL_STATIC(UrlHandler, s_handler) static void initializeGlobalSettings() { QDesktopServices::setUrlHandler(QStringLiteral("help"), s_handler, "openHelp"); } Q_COREAPP_STARTUP_FUNCTION(initializeGlobalSettings) #include "urlhandler.moc" diff --git a/tests/kmodifierkeyinfotest.cpp b/tests/kmodifierkeyinfotest.cpp index c2852dd..918dc16 100644 --- a/tests/kmodifierkeyinfotest.cpp +++ b/tests/kmodifierkeyinfotest.cpp @@ -1,199 +1,199 @@ /* Copyright 2009 Michael Leupold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include "kmodifierkeyinfo.h" template class Triple { public: Triple() {} Triple(const A _first, const B _second, const C _third) : first(_first), second(_second), third(_third) {}; A first; B second; C third; }; class TestWidget : public QWidget { Q_OBJECT public: TestWidget(); protected Q_SLOTS: void keyPressed(Qt::Key key, bool state); void keyLatched(Qt::Key key, bool state); void keyLocked(Qt::Key key, bool state); void mouseButtonPressed(Qt::MouseButton button, bool state); void latch(); void lock(); void keyAdded(Qt::Key) { qDebug() << "Key added"; } void keyRemoved(Qt::Key) { qDebug() << "Key removed"; } private: KModifierKeyInfo m_lock; QMap > m_leds; QMap m_mouseLeds; }; -TestWidget::TestWidget() : QWidget(0), m_lock(this) +TestWidget::TestWidget() : QWidget(nullptr), m_lock(this) { QMap mods; mods.insert(Qt::Key_Shift, QStringLiteral("Shift")); mods.insert(Qt::Key_Control, QStringLiteral("Ctrl")); mods.insert(Qt::Key_Alt, QStringLiteral("Alt")); mods.insert(Qt::Key_Meta, QStringLiteral("Meta")); mods.insert(Qt::Key_Super_L, QStringLiteral("Super")); mods.insert(Qt::Key_Hyper_L, QStringLiteral("Hyper")); mods.insert(Qt::Key_AltGr, QStringLiteral("AltGr")); mods.insert(Qt::Key_NumLock, QStringLiteral("NumLock")); mods.insert(Qt::Key_CapsLock, QStringLiteral("CapsLock")); mods.insert(Qt::Key_ScrollLock, QStringLiteral("ScrollLock")); QMap buttons; buttons.insert(Qt::LeftButton, QStringLiteral("Left Button")); buttons.insert(Qt::RightButton, QStringLiteral("Right Button")); buttons.insert(Qt::MidButton, QStringLiteral("Middle Button")); buttons.insert(Qt::XButton1, QStringLiteral("First X Button")); buttons.insert(Qt::XButton2, QStringLiteral("Second X Button")); QVBoxLayout *layout = new QVBoxLayout(this); QMap::const_iterator it; QMap::const_iterator end = mods.constEnd(); for (it = mods.constBegin(); it != end; ++it) { if (m_lock.knowsKey(it.key())) { QHBoxLayout *hlayout = new QHBoxLayout; QCheckBox *pressed = new QCheckBox(this); QCheckBox *latched = new QCheckBox(this); QCheckBox *locked = new QCheckBox(this); QPushButton *latch = new QPushButton(QStringLiteral("latch"), this); latch->setProperty("modifier", it.key()); connect(latch, SIGNAL(clicked()), SLOT(latch())); QPushButton *lock = new QPushButton(QStringLiteral("lock"), this); lock->setProperty("modifier", it.key()); connect(lock, SIGNAL(clicked()), SLOT(lock())); pressed->setChecked(m_lock.isKeyPressed(it.key())); latched->setChecked(m_lock.isKeyLatched(it.key())); locked->setChecked(m_lock.isKeyLocked(it.key())); m_leds.insert(it.key(), Triple(pressed, latched, locked)); hlayout->addWidget(pressed); hlayout->addWidget(latched); hlayout->addWidget(locked); hlayout->addWidget(new QLabel(it.value())); hlayout->addWidget(latch); hlayout->addWidget(lock); layout->addLayout(hlayout); } } QMap::const_iterator it2; QMap::const_iterator end2 = buttons.constEnd(); for (it2 = buttons.constBegin(); it2 != end2; ++it2) { QHBoxLayout *hlayout = new QHBoxLayout; QCheckBox *pressed = new QCheckBox(this); pressed->setChecked(m_lock.isButtonPressed(it2.key())); m_mouseLeds.insert(it2.key(), pressed); hlayout->addWidget(pressed); hlayout->addWidget(new QLabel(it2.value())); layout->addLayout(hlayout); } setLayout(layout); connect(&m_lock, SIGNAL(keyPressed(Qt::Key,bool)), SLOT(keyPressed(Qt::Key,bool))); connect(&m_lock, SIGNAL(keyLatched(Qt::Key,bool)), SLOT(keyLatched(Qt::Key,bool))); connect(&m_lock, SIGNAL(keyLocked(Qt::Key,bool)), SLOT(keyLocked(Qt::Key,bool))); connect(&m_lock, SIGNAL(buttonPressed(Qt::MouseButton,bool)), SLOT(mouseButtonPressed(Qt::MouseButton,bool))); connect(&m_lock, SIGNAL(keyAdded(Qt::Key)), SLOT(keyAdded(Qt::Key))); connect(&m_lock, SIGNAL(keyRemoved(Qt::Key)), SLOT(keyRemoved(Qt::Key))); } void TestWidget::keyPressed(Qt::Key key, bool pressed) { if (m_leds.contains(key)) { m_leds[key].first->setChecked(pressed); } } void TestWidget::keyLatched(Qt::Key key, bool latched) { if (m_leds.contains(key)) { m_leds[key].second->setChecked(latched); } } void TestWidget::keyLocked(Qt::Key key, bool locked) { if (m_leds.contains(key)) { m_leds[key].third->setChecked(locked); } } void TestWidget::mouseButtonPressed(Qt::MouseButton button, bool pressed) { if (m_mouseLeds.contains(button)) { m_mouseLeds[button]->setChecked(pressed); } } void TestWidget::latch() { Qt::Key key = (Qt::Key)sender()->property("modifier").toInt(); m_lock.setKeyLatched(key, !m_lock.isKeyLatched(key)); } void TestWidget::lock() { Qt::Key key = (Qt::Key)sender()->property("modifier").toInt(); m_lock.setKeyLocked(key, !m_lock.isKeyLocked(key)); } int main(int argc, char *argv[]) { QApplication::setApplicationName(QStringLiteral("simple")); QApplication app(argc, argv); TestWidget mainWidget; mainWidget.show(); return app.exec(); } #include "kmodifierkeyinfotest.moc"