diff options
Diffstat (limited to 'src/gui')
45 files changed, 2654 insertions, 1353 deletions
diff --git a/src/gui/configure.json b/src/gui/configure.json index 7f4d7cc6af..3891ff4070 100644 --- a/src/gui/configure.json +++ b/src/gui/configure.json @@ -1637,15 +1637,9 @@ "condition": "features.imageformat_xpm", "output": [ "publicFeature", "feature" ] }, - "shortcut": { - "label": "QShortcut", - "purpose": "Provides keyboard accelerators and shortcuts.", - "section": "Kernel", - "output": [ "publicFeature", "feature" ] - }, "action": { - "label": "QAction", - "purpose": "Provides widget actions.", + "label": "Q(Gui)Action(Group)", + "purpose": "Provides abstract user interface actions.", "section": "Kernel", "output": [ "publicFeature", "feature" ] }, diff --git a/src/gui/doc/snippets/picture/picture.cpp b/src/gui/doc/snippets/picture/picture.cpp index 863476fdbf..807c263b19 100644 --- a/src/gui/doc/snippets/picture/picture.cpp +++ b/src/gui/doc/snippets/picture/picture.cpp @@ -80,82 +80,3 @@ int main() painter.end(); // painting done //! [1] } - - QPicture myPicture; - { - // FORMATS -//! [2] - const QStringList list = QPicture::inputFormatList(); - for (const QString &string : list) - myProcessing(string); -//! [2] - } - - { - // OUTPUT -//! [3] - const QStringList list = QPicture::outputFormatList(); - for (const QString &string : list) - myProcessing(string); -//! [3] - } - - { - // PIC READ -//! [4] - QPictureIO iio; - QPixmap pixmap; - iio.setFileName("vegeburger.pic"); - if (iio.read()) { // OK - QPicture picture = iio.picture(); - QPainter painter(&pixmap); - painter.drawPicture(0, 0, picture); - } -//! [4] - } - - { - QPixmap pixmap; - // PIC WRITE -//! [5] - QPictureIO iio; - QPicture picture; - QPainter painter(&picture); - painter.drawPixmap(0, 0, pixmap); - iio.setPicture(picture); - iio.setFileName("vegeburger.pic"); - iio.setFormat("PIC"); - if (iio.write()) - return true; // returned true if written successfully -//! [5] - } - -} - -// SVG READ -//! [6] -void readSVG(QPictureIO *picture) -{ - // read the picture using the picture->ioDevice() -} -//! [6] - -// SVG WRITE -//! [7] -void writeSVG(QPictureIO *picture) -{ - // write the picture using the picture->ioDevice() -} -//! [7] - -// USE SVG -void foo() { - -//! [8] - // add the SVG picture handler - // ... -//! [8] - QPictureIO::defineIOHandler("SVG", 0, 0, readSVG, writeSVG); - // ... - -} diff --git a/src/gui/image/image.pri b/src/gui/image/image.pri index 1f42f28d1e..760b737ec3 100644 --- a/src/gui/image/image.pri +++ b/src/gui/image/image.pri @@ -14,7 +14,6 @@ HEADERS += \ image/qpaintengine_pic_p.h \ image/qpicture.h \ image/qpicture_p.h \ - image/qpictureformatplugin.h \ image/qpixmap.h \ image/qpixmap_raster_p.h \ image/qpixmap_blitter_p.h \ @@ -38,7 +37,6 @@ SOURCES += \ image/qimagewriter.cpp \ image/qpaintengine_pic.cpp \ image/qpicture.cpp \ - image/qpictureformatplugin.cpp \ image/qpixmap.cpp \ image/qpixmapcache.cpp \ image/qplatformpixmap.cpp \ @@ -59,9 +57,6 @@ win32:!winrt: SOURCES += image/qpixmap_win.cpp darwin: OBJECTIVE_SOURCES += image/qimage_darwin.mm -NO_PCH_SOURCES += image/qimage_compat.cpp -false: SOURCES += $$NO_PCH_SOURCES # Hack for QtCreator - # Built-in image format support HEADERS += \ image/qbmphandler_p.h \ diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 7544ccca05..73c960f13f 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -68,7 +68,6 @@ class QMatrix; class QStringList; class QTransform; class QVariant; -template <class T> class QList; template <class T> class QVector; struct QImageData; @@ -179,7 +178,6 @@ public: Format format() const; -#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QIMAGE_COMPAT_CPP) Q_REQUIRED_RESULT Q_ALWAYS_INLINE QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const & { return convertToFormat_helper(f, flags); } Q_REQUIRED_RESULT Q_ALWAYS_INLINE QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) && @@ -189,9 +187,6 @@ public: else return convertToFormat_helper(f, flags); } -#else - Q_REQUIRED_RESULT QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const; -#endif Q_REQUIRED_RESULT QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const; bool reinterpretAsFormat(Format f); @@ -284,7 +279,6 @@ public: static QMatrix trueMatrix(const QMatrix &, int w, int h); QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; static QTransform trueMatrix(const QTransform &, int w, int h); -#if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QIMAGE_COMPAT_CPP) QImage mirrored(bool horizontally = false, bool vertically = true) const & { return mirrored_helper(horizontally, vertically); } QImage &&mirrored(bool horizontally = false, bool vertically = true) && @@ -293,10 +287,6 @@ public: { return rgbSwapped_helper(); } QImage &&rgbSwapped() && { rgbSwapped_inplace(); return std::move(*this); } -#else - QImage mirrored(bool horizontally = false, bool vertically = true) const; - QImage rgbSwapped() const; -#endif void invertPixels(InvertMode = InvertRgb); QColorSpace colorSpace() const; diff --git a/src/gui/image/qimage_p.h b/src/gui/image/qimage_p.h index 0930955f5a..9277472c3c 100644 --- a/src/gui/image/qimage_p.h +++ b/src/gui/image/qimage_p.h @@ -140,7 +140,7 @@ QImageData::calculateImageParameters(qsizetype width, qsizetype height, qsizetyp qsizetype dummy; if (mul_overflow(height, qsizetype(sizeof(uchar *)), &dummy)) return invalid; // why is this here? -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) +#if 1 || QT_VERSION < QT_VERSION_CHECK(6,0,0) // ### can only fix this if QImage dimensions are not int anymore // Disallow images where width * depth calculations might overflow if (width > (INT_MAX - 31) / depth) return invalid; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 978a07b9f9..e119103462 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -264,14 +264,14 @@ void QPicture::setData(const char* data, uint size) \sa save() */ -bool QPicture::load(const QString &fileName, const char *format) +bool QPicture::load(const QString &fileName) { QFile f(fileName); if (!f.open(QIODevice::ReadOnly)) { operator=(QPicture()); return false; } - return load(&f, format); + return load(&f); } /*! @@ -280,21 +280,8 @@ bool QPicture::load(const QString &fileName, const char *format) \a dev is the device to use for loading. */ -bool QPicture::load(QIODevice *dev, const char *format) +bool QPicture::load(QIODevice *dev) { - if(format) { -#ifndef QT_NO_PICTUREIO - QPictureIO io(dev, format); - if (io.read()) { - operator=(io.picture()); - return true; - } -#endif - qWarning("QPicture::load: No such picture format: %s", format); - operator=(QPicture()); - return false; - } - detach(); QByteArray a = dev->readAll(); @@ -312,7 +299,7 @@ bool QPicture::load(QIODevice *dev, const char *format) \sa load() */ -bool QPicture::save(const QString &fileName, const char *format) +bool QPicture::save(const QString &fileName) { if (paintingActive()) { qWarning("QPicture::save: still being painted on. " @@ -320,27 +307,10 @@ bool QPicture::save(const QString &fileName, const char *format) return false; } - - if(format) { -#ifndef QT_NO_PICTUREIO - QPictureIO io(fileName, format); - bool result = io.write(); - if (result) { - operator=(io.picture()); - } else if (format) -#else - bool result = false; -#endif - { - qWarning("QPicture::save: No such picture format: %s", format); - } - return result; - } - QFile f(fileName); if (!f.open(QIODevice::WriteOnly)) return false; - return save(&f, format); + return save(&f); } /*! @@ -349,7 +319,7 @@ bool QPicture::save(const QString &fileName, const char *format) \a dev is the device to use for saving. */ -bool QPicture::save(QIODevice *dev, const char *format) +bool QPicture::save(QIODevice *dev) { if (paintingActive()) { qWarning("QPicture::save: still being painted on. " @@ -357,22 +327,6 @@ bool QPicture::save(QIODevice *dev, const char *format) return false; } - if(format) { -#ifndef QT_NO_PICTUREIO - QPictureIO io(dev, format); - bool result = io.write(); - if (result) { - operator=(io.picture()); - } else if (format) -#else - bool result = false; -#endif - { - qWarning("QPicture::save: No such picture format: %s", format); - } - return result; - } - dev->write(d_func()->pictb.buffer(), d_func()->pictb.buffer().size()); return true; } @@ -1189,780 +1143,6 @@ QDataStream &operator>>(QDataStream &s, QPicture &r) } #endif // QT_NO_DATASTREAM - -#ifndef QT_NO_PICTUREIO - -QT_BEGIN_INCLUDE_NAMESPACE -#include "qregexp.h" -#include "qpictureformatplugin.h" -QT_END_INCLUDE_NAMESPACE - -#if QT_DEPRECATED_SINCE(5, 10) -/*! - \obsolete - - Returns a string that specifies the picture format of the file \a - fileName, or \nullptr if the file cannot be read or if the format - is not recognized. - - \sa load(), save() -*/ - -const char* QPicture::pictureFormat(const QString &fileName) -{ - const QByteArray format = QPictureIO::pictureFormat(fileName); - // This function returns a const char * from a QByteArray. - // Double check that the QByteArray is not detached, otherwise - // we would return a dangling pointer. - Q_ASSERT(!format.isDetached()); - return format; -} - -/*! - \obsolete - - Returns a list of picture formats that are supported for picture - input. - - \sa outputFormats(), inputFormatList(), QPictureIO -*/ -QList<QByteArray> QPicture::inputFormats() -{ - return QPictureIO::inputFormats(); -} - -static QStringList qToStringList(const QList<QByteArray> &arr) -{ - QStringList list; - const int count = arr.count(); - list.reserve(count); - for (int i = 0; i < count; ++i) - list.append(QString::fromLatin1(arr.at(i))); - return list; -} - -/*! - \obsolete - - Returns a list of picture formats that are supported for picture - input. - - Note that if you want to iterate over the list, you should iterate - over a copy, e.g. - \snippet picture/picture.cpp 2 - - \sa outputFormatList(), inputFormats(), QPictureIO -*/ -QStringList QPicture::inputFormatList() -{ - return qToStringList(QPictureIO::inputFormats()); -} - - -/*! - \obsolete - - Returns a list of picture formats that are supported for picture - output. - - Note that if you want to iterate over the list, you should iterate - over a copy, e.g. - \snippet picture/picture.cpp 3 - - \sa inputFormatList(), outputFormats(), QPictureIO -*/ -QStringList QPicture::outputFormatList() -{ - return qToStringList(QPictureIO::outputFormats()); -} - -/*! - \obsolete - - Returns a list of picture formats that are supported for picture - output. - - \sa inputFormats(), outputFormatList(), QPictureIO -*/ -QList<QByteArray> QPicture::outputFormats() -{ - return QPictureIO::outputFormats(); -} -#endif // QT_DEPRECATED_SINCE(5, 10) - -/***************************************************************************** - QPictureIO member functions - *****************************************************************************/ - -/*! - \obsolete - - \class QPictureIO - - \brief The QPictureIO class contains parameters for loading and - saving pictures. - - \ingroup painting - \ingroup io - \inmodule QtGui - - QPictureIO contains a QIODevice object that is used for picture data - I/O. The programmer can install new picture file formats in addition - to those that Qt provides. - - You don't normally need to use this class; QPicture::load(), - QPicture::save(). - - \sa QPicture, QPixmap, QFile -*/ - -struct QPictureIOData -{ - QPicture pi; // picture - int iostat; // IO status - QByteArray frmt; // picture format - QIODevice *iodev; // IO device - QString fname; // file name - QString descr; // picture description - const char *parameters; - int quality; - float gamma; -}; - -/*! - Constructs a QPictureIO object with all parameters set to zero. -*/ - -QPictureIO::QPictureIO() -{ - init(); -} - -/*! - Constructs a QPictureIO object with the I/O device \a ioDevice and a - \a format tag. -*/ - -QPictureIO::QPictureIO(QIODevice *ioDevice, const char *format) -{ - init(); - d->iodev = ioDevice; - d->frmt = format; -} - -/*! - Constructs a QPictureIO object with the file name \a fileName and a - \a format tag. -*/ - -QPictureIO::QPictureIO(const QString &fileName, const char* format) -{ - init(); - d->frmt = format; - d->fname = fileName; -} - -/*! - Contains initialization common to all QPictureIO constructors. -*/ - -void QPictureIO::init() -{ - d = new QPictureIOData(); - d->parameters = 0; - d->quality = -1; // default quality of the current format - d->gamma=0.0f; - d->iostat = 0; - d->iodev = 0; -} - -/*! - Destroys the object and all related data. -*/ - -QPictureIO::~QPictureIO() -{ - if (d->parameters) - delete [] d->parameters; - delete d; -} - - -/***************************************************************************** - QPictureIO picture handler functions - *****************************************************************************/ - -class QPictureHandler -{ -public: - QPictureHandler(const char *f, const char *h, const QByteArray& fl, - picture_io_handler r, picture_io_handler w); - QByteArray format; // picture format - QRegExp header; // picture header pattern - enum TMode { Untranslated=0, TranslateIn, TranslateInOut } text_mode; - picture_io_handler read_picture; // picture read function - picture_io_handler write_picture; // picture write function - bool obsolete; // support not "published" -}; - -QPictureHandler::QPictureHandler(const char *f, const char *h, const QByteArray& fl, - picture_io_handler r, picture_io_handler w) - : format(f), header(QString::fromLatin1(h)) -{ - text_mode = Untranslated; - if (fl.contains('t')) - text_mode = TranslateIn; - else if (fl.contains('T')) - text_mode = TranslateInOut; - obsolete = fl.contains('O'); - read_picture = r; - write_picture = w; -} - -typedef QList<QPictureHandler *> QPHList; -Q_GLOBAL_STATIC(QPHList, pictureHandlers) - -void qt_init_picture_plugins() -{ - typedef QMultiMap<int, QString> PluginKeyMap; - typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; - - static QBasicMutex mutex; - const auto locker = qt_scoped_lock(mutex); - static QFactoryLoader loader(QPictureFormatInterface_iid, - QStringLiteral("/pictureformats")); - - const PluginKeyMap keyMap = loader.keyMap(); - const PluginKeyMapConstIterator cend = keyMap.constEnd(); - for (PluginKeyMapConstIterator it = keyMap.constBegin(); it != cend; ++it) { - if (QPictureFormatPlugin *format = qobject_cast<QPictureFormatPlugin*>(loader.instance(it.key()))) - format->installIOHandler(it.value()); - } -} - -static void cleanup() -{ - // make sure that picture handlers are delete before plugin manager - if (QPHList *list = pictureHandlers()) { - qDeleteAll(*list); - list->clear(); - } -} - -void qt_init_picture_handlers() // initialize picture handlers -{ - static QBasicAtomicInt done = Q_BASIC_ATOMIC_INITIALIZER(0); - if (done.testAndSetRelaxed(0, 1)) { - qAddPostRoutine(cleanup); - } -} - -static QPictureHandler *get_picture_handler(const char *format) -{ // get pointer to handler - qt_init_picture_handlers(); - qt_init_picture_plugins(); - if (QPHList *list = pictureHandlers()) { - for (int i = 0; i < list->size(); ++i) { - if (list->at(i)->format == format) - return list->at(i); - } - } - return 0; // no such handler -} - - -/*! - Defines a picture I/O handler for the picture format called \a - format, which is recognized using the regular - expression defined in \a header, read using \a readPicture and - written using \a writePicture. - - \a flags is a string of single-character flags for this format. - The only flag defined currently is T (upper case), so the only - legal value for \a flags are "T" and the empty string. The "T" - flag means that the picture file is a text file, and Qt should treat - all newline conventions as equivalent. (XPM files and some PPM - files are text files for example.) - - \a format is used to select a handler to write a QPicture; \a header - is used to select a handler to read an picture file. - - If \a readPicture is \nullptr, the QPictureIO will not be able - to read pictures in \a format. If \a writePicture is \nullptr, - the QPictureIO will not be able to write pictures in \a format. If - both are null, the QPictureIO object is valid but useless. - - Example: - \snippet picture/picture.cpp 6 - \codeline - \snippet picture/picture.cpp 7 - \codeline - \snippet picture/picture.cpp 8 - - Before the regular expression test, all the 0 bytes in the file header are - converted to 1 bytes. This is done because when Qt was ASCII-based, QRegExp - could not handle 0 bytes in strings. - - The regexp is only applied on the first 14 bytes of the file. - - (Note that if one handlerIO supports writing a format and another - supports reading it, Qt supports both reading and writing. If two - handlers support the same operation, Qt chooses one arbitrarily.) -*/ - -void QPictureIO::defineIOHandler(const char *format, - const char *header, - const char *flags, - picture_io_handler readPicture, - picture_io_handler writePicture) -{ - qt_init_picture_handlers(); - if (QPHList *list = pictureHandlers()) { - QPictureHandler *p; - p = new QPictureHandler(format, header, QByteArray(flags), readPicture, writePicture); - list->prepend(p); - } -} - - -/***************************************************************************** - QPictureIO normal member functions - *****************************************************************************/ - -/*! - Returns the picture currently set. - - \sa setPicture() -*/ -const QPicture &QPictureIO::picture() const { return d->pi; } - -/*! - Returns the picture's IO status. A non-zero value indicates an - error, whereas 0 means that the IO operation was successful. - - \sa setStatus() -*/ -int QPictureIO::status() const { return d->iostat; } - -/*! - Returns the picture format string or \nullptr if no format has been - explicitly set. -*/ -const char *QPictureIO::format() const { return d->frmt; } - -/*! - Returns the IO device currently set. - - \sa setIODevice() -*/ -QIODevice *QPictureIO::ioDevice() const { return d->iodev; } - -/*! - Returns the file name currently set. - - \sa setFileName() -*/ -QString QPictureIO::fileName() const { return d->fname; } - - -/*! - Returns the picture description string. - - \sa setDescription() -*/ -QString QPictureIO::description() const { return d->descr; } - -/*! - Sets the picture to \a picture. - - \sa picture() -*/ -void QPictureIO::setPicture(const QPicture &picture) -{ - d->pi = picture; -} - -/*! - Sets the picture IO status to \a status. A non-zero value indicates - an error, whereas 0 means that the IO operation was successful. - - \sa status() -*/ -void QPictureIO::setStatus(int status) -{ - d->iostat = status; -} - -/*! - Sets the picture format to \a format for the picture to be read or - written. - - It is necessary to specify a format before writing an picture, but - it is not necessary to specify a format before reading an picture. - - If no format has been set, Qt guesses the picture format before - reading it. If a format is set the picture will only be read if it - has that format. - - \sa read(), write(), format() -*/ -void QPictureIO::setFormat(const char *format) -{ - d->frmt = format; -} - -/*! - Sets the IO device to be used for reading or writing an picture. - - Setting the IO device allows pictures to be read/written to any - block-oriented QIODevice. - - If \a ioDevice is not null, this IO device will override file name - settings. - - \sa setFileName() -*/ -void QPictureIO::setIODevice(QIODevice *ioDevice) -{ - d->iodev = ioDevice; -} - -/*! - Sets the name of the file to read or write an picture from to \a - fileName. - - \sa setIODevice() -*/ -void QPictureIO::setFileName(const QString &fileName) -{ - d->fname = fileName; -} - -/*! - Returns the quality of the written picture, related to the - compression ratio. - - \sa setQuality(), QPicture::save() -*/ -int QPictureIO::quality() const -{ - return d->quality; -} - -/*! - Sets the quality of the written picture to \a q, related to the - compression ratio. - - \a q must be in the range -1..100. Specify 0 to obtain small - compressed files, 100 for large uncompressed files. (-1 signifies - the default compression.) - - \sa quality(), QPicture::save() -*/ - -void QPictureIO::setQuality(int q) -{ - d->quality = q; -} - -/*! - Returns the picture's parameters string. - - \sa setParameters() -*/ - -const char *QPictureIO::parameters() const -{ - return d->parameters; -} - -/*! - Sets the picture's parameter string to \a parameters. This is for - picture handlers that require special parameters. - - Although the current picture formats supported by Qt ignore the - parameters string, it may be used in future extensions or by - contributions (for example, JPEG). - - \sa parameters() -*/ - -void QPictureIO::setParameters(const char *parameters) -{ - if (d->parameters) - delete [] d->parameters; - d->parameters = qstrdup(parameters); -} - -/*! - Sets the gamma value at which the picture will be viewed to \a - gamma. If the picture format stores a gamma value for which the - picture is intended to be used, then this setting will be used to - modify the picture. Setting to 0.0 will disable gamma correction - (i.e. any specification in the file will be ignored). - - The default value is 0.0. - - \sa gamma() -*/ -void QPictureIO::setGamma(float gamma) -{ - d->gamma=gamma; -} - -/*! - Returns the gamma value at which the picture will be viewed. - - \sa setGamma() -*/ -float QPictureIO::gamma() const -{ - return d->gamma; -} - -/*! - Sets the picture description string for picture handlers that support - picture descriptions to \a description. - - Currently, no picture format supported by Qt uses the description - string. -*/ - -void QPictureIO::setDescription(const QString &description) -{ - d->descr = description; -} - - -/*! - Returns a string that specifies the picture format of the file \a - fileName, or null if the file cannot be read or if the format is - not recognized. -*/ - -QByteArray QPictureIO::pictureFormat(const QString &fileName) -{ - QFile file(fileName); - QByteArray format; - if (!file.open(QIODevice::ReadOnly)) - return format; - format = pictureFormat(&file); - file.close(); - return format; -} - -/*! - \overload - - Returns a string that specifies the picture format of the picture read - from IO device \a d, or 0 if the device cannot be read or if the - format is not recognized. - - Make sure that \a d is at the right position in the device (for - example, at the beginning of the file). - - \sa QIODevice::pos() -*/ - -QByteArray QPictureIO::pictureFormat(QIODevice *d) -{ - // if you change this change the documentation for defineIOHandler() - const int buflen = 14; - - char buf[buflen]; - char buf2[buflen]; - qt_init_picture_handlers(); - qt_init_picture_plugins(); - int pos = d->pos(); // save position - int rdlen = d->read(buf, buflen); // read a few bytes - - QByteArray format; - if (rdlen != buflen) - return format; - - memcpy(buf2, buf, buflen); - - for (int n = 0; n < rdlen; n++) - if (buf[n] == '\0') - buf[n] = '\001'; - if (rdlen > 0) { - buf[rdlen - 1] = '\0'; - QString bufStr = QString::fromLatin1(buf); - if (QPHList *list = pictureHandlers()) { - for (int i = 0; i < list->size(); ++i) { - if (list->at(i)->header.indexIn(bufStr) != -1) { // try match with headers - format = list->at(i)->format; - break; - } - } - } - } - d->seek(pos); // restore position - return format; -} - -/*! - Returns a sorted list of picture formats that are supported for - picture input. -*/ -QList<QByteArray> QPictureIO::inputFormats() -{ - QList<QByteArray> result; - - qt_init_picture_handlers(); - qt_init_picture_plugins(); - - if (QPHList *list = pictureHandlers()) { - for (int i = 0; i < list->size(); ++i) { - QPictureHandler *p = list->at(i); - if (p->read_picture && !p->obsolete && !result.contains(p->format)) - result.append(p->format); - } - } - std::sort(result.begin(), result.end()); - - return result; -} - -/*! - Returns a sorted list of picture formats that are supported for - picture output. -*/ -QList<QByteArray> QPictureIO::outputFormats() -{ - qt_init_picture_handlers(); - qt_init_picture_plugins(); - - QList<QByteArray> result; - if (QPHList *list = pictureHandlers()) { - for (int i = 0; i < list->size(); ++i) { - QPictureHandler *p = list->at(i); - if (p->write_picture && !p->obsolete && !result.contains(p->format)) - result.append(p->format); - } - } - return result; -} - - - -/*! - Reads an picture into memory and returns \c true if the picture was - successfully read; otherwise returns \c false. - - Before reading an picture you must set an IO device or a file name. - If both an IO device and a file name have been set, the IO device - will be used. - - Setting the picture file format string is optional. - - Note that this function does \e not set the \l{format()}{format} used to read the picture. If you need that - information, use the pictureFormat() static functions. - - Example: - - \snippet picture/picture.cpp 4 - - \sa setIODevice(), setFileName(), setFormat(), write(), QPixmap::load() -*/ -bool QPictureIO::read() -{ - QFile file; - QByteArray picture_format; - QPictureHandler *h; - - if (d->iodev) { // read from io device - // ok, already open - } else if (!d->fname.isEmpty()) { // read from file - file.setFileName(d->fname); - if (!file.open(QIODevice::ReadOnly)) - return false; // cannot open file - d->iodev = &file; - } else { // no file name or io device - return false; - } - if (d->frmt.isEmpty()) { - // Try to guess format - picture_format = pictureFormat(d->iodev); // get picture format - if (picture_format.isEmpty()) { - if (file.isOpen()) { // unknown format - file.close(); - d->iodev = 0; - } - return false; - } - } else { - picture_format = d->frmt; - } - - h = get_picture_handler(picture_format); - if (file.isOpen()) { -#if !defined(Q_OS_UNIX) - if (h && h->text_mode) { // reopen in translated mode - file.close(); - file.open(QIODevice::ReadOnly | QIODevice::Text); - } - else -#endif - file.seek(0); // position to start - } - d->iostat = 1; // assume error - - if (h && h->read_picture) - (*h->read_picture)(this); - - if (file.isOpen()) { // picture was read using file - file.close(); - d->iodev = 0; - } - return d->iostat == 0; // picture successfully read? -} - - -/*! - Writes an picture to an IO device and returns \c true if the picture was - successfully written; otherwise returns \c false. - - Before writing an picture you must set an IO device or a file name. - If both an IO device and a file name have been set, the IO device - will be used. - - The picture will be written using the specified picture format. - - Example: - \snippet picture/picture.cpp 5 - - \sa setIODevice(), setFileName(), setFormat(), read(), QPixmap::save() -*/ -bool QPictureIO::write() -{ - if (d->frmt.isEmpty()) - return false; - QPictureHandler *h = get_picture_handler(d->frmt); - if (!h || !h->write_picture) { - qWarning("QPictureIO::write: No such picture format handler: %s", - format()); - return false; - } - QFile file; - if (!d->iodev && !d->fname.isEmpty()) { - file.setFileName(d->fname); - bool translate = h->text_mode==QPictureHandler::TranslateInOut; - QIODevice::OpenMode fmode = translate ? QIODevice::WriteOnly | QIODevice::Text : QIODevice::OpenMode(QIODevice::WriteOnly); - if (!file.open(fmode)) // couldn't create file - return false; - d->iodev = &file; - } - d->iostat = 1; - (*h->write_picture)(this); - if (file.isOpen()) { // picture was written using file - file.close(); - d->iodev = 0; - } - return d->iostat == 0; // picture successfully written? -} -#endif //QT_NO_PICTUREIO - QT_END_NAMESPACE #endif // QT_NO_PICTURE diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h index 189e57b9a3..34860985ed 100644 --- a/src/gui/image/qpicture.h +++ b/src/gui/image/qpicture.h @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE - #ifndef QT_NO_PICTURE class QPicturePrivate; @@ -69,10 +68,10 @@ public: bool play(QPainter *p); - bool load(QIODevice *dev, const char *format = nullptr); - bool load(const QString &fileName, const char *format = nullptr); - bool save(QIODevice *dev, const char *format = nullptr); - bool save(const QString &fileName, const char *format = nullptr); + bool load(QIODevice *dev); + bool load(const QString &fileName); + bool save(QIODevice *dev); + bool save(const QString &fileName); QRect boundingRect() const; void setBoundingRect(const QRect &r); @@ -88,14 +87,6 @@ public: friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &in, const QPicture &p); friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QPicture &p); -#if QT_DEPRECATED_SINCE(5, 10) - static QT_DEPRECATED const char* pictureFormat(const QString &fileName); - static QT_DEPRECATED QList<QByteArray> inputFormats(); - static QT_DEPRECATED QList<QByteArray> outputFormats(); - static QT_DEPRECATED QStringList inputFormatList(); - static QT_DEPRECATED QStringList outputFormatList(); -#endif // QT_DEPRECATED_SINCE(5, 10) - QPaintEngine *paintEngine() const override; protected: @@ -118,67 +109,6 @@ public: Q_DECLARE_SHARED(QPicture) - -#ifndef QT_NO_PICTUREIO -class QIODevice; -class QPictureIO; -typedef void (*picture_io_handler)(QPictureIO *); // picture IO handler - -struct QPictureIOData; - -class Q_GUI_EXPORT QPictureIO -{ -public: - QPictureIO(); - QPictureIO(QIODevice *ioDevice, const char *format); - QPictureIO(const QString &fileName, const char *format); - ~QPictureIO(); - - const QPicture &picture() const; - int status() const; - const char *format() const; - QIODevice *ioDevice() const; - QString fileName() const; - int quality() const; - QString description() const; - const char *parameters() const; - float gamma() const; - - void setPicture(const QPicture &); - void setStatus(int); - void setFormat(const char *); - void setIODevice(QIODevice *); - void setFileName(const QString &); - void setQuality(int); - void setDescription(const QString &); - void setParameters(const char *); - void setGamma(float); - - bool read(); - bool write(); - - static QByteArray pictureFormat(const QString &fileName); - static QByteArray pictureFormat(QIODevice *); - static QList<QByteArray> inputFormats(); - static QList<QByteArray> outputFormats(); - - static void defineIOHandler(const char *format, - const char *header, - const char *flags, - picture_io_handler read_picture, - picture_io_handler write_picture); - -private: - Q_DISABLE_COPY(QPictureIO) - - void init(); - - QPictureIOData *d; -}; - -#endif //QT_NO_PICTUREIO - - /***************************************************************************** QPicture stream functions *****************************************************************************/ diff --git a/src/gui/image/qpictureformatplugin.cpp b/src/gui/image/qpictureformatplugin.cpp deleted file mode 100644 index ef57ad720f..0000000000 --- a/src/gui/image/qpictureformatplugin.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qpictureformatplugin.h" -#if !defined(QT_NO_PICTURE) -#include "qpicture.h" - -QT_BEGIN_NAMESPACE - -/*! - \obsolete - - \class QPictureFormatPlugin - \brief The QPictureFormatPlugin class provides an abstract base - for custom picture format plugins. - - \ingroup plugins - \inmodule QtGui - - The picture format plugin is a simple plugin interface that makes - it easy to create custom picture formats that can be used - transparently by applications. - - Writing an picture format plugin is achieved by subclassing this - base class, reimplementing the pure virtual functions - loadPicture(), savePicture(), and installIOHandler(), and - exporting the class with the Q_PLUGIN_METADATA() macro. - - The json file containing the metadata should contain one entry - with the list of picture formats supported by the plugin: - - \code - { "Keys": [ "mypictureformat" ] } - \endcode - - \sa {How to Create Qt Plugins} -*/ - -/*! - \fn bool QPictureFormatPlugin::installIOHandler(const QString &format) - - Installs a QPictureIO picture I/O handler for the picture format \a - format. Returns \c true on success. -*/ - - -/*! - Constructs an picture format plugin with the given \a parent. - This is invoked automatically by the moc generated code that exports the plugin. -*/ -QPictureFormatPlugin::QPictureFormatPlugin(QObject *parent) - : QObject(parent) -{ -} - -/*! - Destroys the picture format plugin. - - You never have to call this explicitly. Qt destroys a plugin - automatically when it is no longer used. -*/ -QPictureFormatPlugin::~QPictureFormatPlugin() -{ -} - - -/*! - Loads the picture stored in the file called \a fileName, with the - given \a format, into *\a picture. Returns \c true on success; - otherwise returns \c false. - - \sa savePicture() -*/ -bool QPictureFormatPlugin::loadPicture(const QString &format, const QString &fileName, QPicture *picture) -{ - Q_UNUSED(format) - Q_UNUSED(fileName) - Q_UNUSED(picture) - return false; -} - -/*! - Saves the given \a picture into the file called \a fileName, - using the specified \a format. Returns \c true on success; otherwise - returns \c false. - - \sa loadPicture() -*/ -bool QPictureFormatPlugin::savePicture(const QString &format, const QString &fileName, const QPicture &picture) -{ - Q_UNUSED(format) - Q_UNUSED(fileName) - Q_UNUSED(picture) - return false; -} - -#endif // QT_NO_PICTURE - -QT_END_NAMESPACE diff --git a/src/gui/itemmodels/qstandarditemmodel.h b/src/gui/itemmodels/qstandarditemmodel.h index a9ee25da75..f1c6e6df5c 100644 --- a/src/gui/itemmodels/qstandarditemmodel.h +++ b/src/gui/itemmodels/qstandarditemmodel.h @@ -53,8 +53,6 @@ QT_REQUIRE_CONFIG(standarditemmodel); QT_BEGIN_NAMESPACE -template <class T> class QList; - class QStandardItemModel; class QStandardItemPrivate; @@ -344,8 +342,11 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; - // Qt 6: add override keyword - bool clearItemData(const QModelIndex &index); + bool clearItemData(const QModelIndex &index) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + override +#endif + ; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 9c80f1e2cc..3784abdacc 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -48,11 +48,8 @@ HEADERS += \ kernel/qinputmethod.h \ kernel/qinputmethod_p.h \ kernel/qinternalmimedata_p.h \ - kernel/qkeysequence.h \ - kernel/qkeysequence_p.h \ kernel/qkeymapper_p.h \ kernel/qpalette.h \ - kernel/qshortcutmap_p.h \ kernel/qsessionmanager.h \ kernel/qsessionmanager_p.h \ kernel/qwindowdefs.h \ @@ -108,12 +105,10 @@ SOURCES += \ kernel/qevent.cpp \ kernel/qinputmethod.cpp \ kernel/qinternalmimedata.cpp \ - kernel/qkeysequence.cpp \ kernel/qkeymapper.cpp \ kernel/qpalette.cpp \ kernel/qguivariant.cpp \ kernel/qscreen.cpp \ - kernel/qshortcutmap.cpp \ kernel/qstylehints.cpp \ kernel/qtouchdevice.cpp \ kernel/qplatformsharedgraphicscache.cpp \ @@ -131,6 +126,18 @@ SOURCES += \ kernel/qhighdpiscaling.cpp \ kernel/qtestsupport_gui.cpp +qtConfig(action) { + HEADERS += \ + kernel/qguiaction.h \ + kernel/qguiaction_p.h \ + kernel/qguiactiongroup.h \ + kernel/qguiactiongroup_p.h + + SOURCES += \ + kernel/qguiactiongroup.cpp \ + kernel/qguiaction.cpp +} + qtConfig(draganddrop) { HEADERS += \ kernel/qdnd_p.h \ @@ -160,4 +167,17 @@ qtConfig(opengl) { kernel/qopenglwindow.cpp } +qtConfig(shortcut) { + HEADERS += \ + kernel/qguishortcut.h \ + kernel/qguishortcut_p.h \ + kernel/qshortcutmap_p.h \ + kernel/qkeysequence.h \ + kernel/qkeysequence_p.h + SOURCES += \ + kernel/qguishortcut.cpp \ + kernel/qshortcutmap.cpp \ + kernel/qkeysequence.cpp +} + win32:HEADERS+=kernel/qwindowdefs_win.h diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index f555f4dc05..6ff6faf809 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1225,7 +1225,7 @@ Qt::KeyboardModifiers QKeyEvent::modifiers() const return QInputEvent::modifiers(); } -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) /*! \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const \since 4.2 @@ -1241,7 +1241,7 @@ bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const const QList<QKeySequence> bindings = QKeySequence::keyBindings(matchKey); return bindings.contains(QKeySequence(searchkey)); } -#endif // QT_NO_SHORTCUT +#endif // QT_CONFIG(shortcut) /*! @@ -2696,10 +2696,6 @@ QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPoin { } #endif -typedef QHash<const QNativeGestureEvent*, const QTouchDevice*> NativeGestureEventDataHash; -// ### Qt6: move this to a member in QNativeGestureEvent -Q_GLOBAL_STATIC(NativeGestureEventDataHash, g_nativeGestureEventDataHash) - /*! Constructs a native gesture event of type \a type originating from \a device. @@ -2714,27 +2710,20 @@ QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QTouc const QPointF &screenPos, qreal realValue, ulong sequenceId, quint64 intValue) : QInputEvent(QEvent::NativeGesture), mGestureType(type), mLocalPos(localPos), mWindowPos(windowPos), mScreenPos(screenPos), mRealValue(realValue), - mSequenceId(sequenceId), mIntValue(intValue) + mSequenceId(sequenceId), mIntValue(intValue), mDevice(device) { - g_nativeGestureEventDataHash->insert(this, device); } QNativeGestureEvent::~QNativeGestureEvent() -{ - g_nativeGestureEventDataHash->remove(this); -} + = default; /*! + \fn const QTouchDevice *QNativeGestureEvent::device() const \since 5.10 Returns the device. */ -const QTouchDevice *QNativeGestureEvent::device() const -{ - return g_nativeGestureEventDataHash->value(this); -} - /*! \fn QNativeGestureEvent::gestureType() const \since 5.2 @@ -3336,18 +3325,18 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent() /*! \class QActionEvent \brief The QActionEvent class provides an event that is generated - when a QAction is added, removed, or changed. + when a QGuiAction is added, removed, or changed. \ingroup events \inmodule QtGui - Actions can be added to widgets using QWidget::addAction(). This - generates an \l ActionAdded event, which you can handle to provide + Actions can be added to controls, for example by using QWidget::addAction(). + This generates an \l ActionAdded event, which you can handle to provide custom behavior. For example, QToolBar reimplements QWidget::actionEvent() to create \l{QToolButton}s for the actions. - \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions() + \sa QGuiAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions() */ /*! @@ -3358,7 +3347,7 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent() type is ActionAdded, the action is to be inserted before the action \a before. If \a before is 0, the action is appended. */ -QActionEvent::QActionEvent(int type, QAction *action, QAction *before) +QActionEvent::QActionEvent(int type, QGuiAction *action, QGuiAction *before) : QEvent(static_cast<QEvent::Type>(type)), act(action), bef(before) {} @@ -3593,7 +3582,7 @@ QToolBarChangeEvent::~QToolBarChangeEvent() #endif // QT_NO_TOOLBAR -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) /*! Constructs a shortcut event for the given \a key press, @@ -3614,7 +3603,7 @@ QShortcutEvent::~QShortcutEvent() { } -#endif // QT_NO_SHORTCUT +#endif // QT_CONFIG(shortcut) #ifndef QT_NO_DEBUG_STREAM @@ -3968,7 +3957,7 @@ QT_WARNING_POP dbg << ')'; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QEvent::Shortcut: { const QShortcutEvent *se = static_cast<const QShortcutEvent *>(e); dbg << "QShortcutEvent(" << se->key().toString() << ", id=" << se->shortcutId(); diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index f363ece48b..6f3215652b 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -45,7 +45,9 @@ #include <QtGui/qregion.h> #include <QtCore/qnamespace.h> #include <QtCore/qstring.h> -#include <QtGui/qkeysequence.h> +#if QT_CONFIG(shortcut) +# include <QtGui/qkeysequence.h> +#endif #include <QtCore/qcoreevent.h> #include <QtCore/qvariant.h> #include <QtCore/qmap.h> // ### Qt 6: Remove @@ -59,7 +61,7 @@ QT_BEGIN_NAMESPACE -class QAction; +class QGuiAction; #ifndef QT_NO_GESTURES class QGesture; #endif @@ -350,7 +352,7 @@ public: const QPointF &windowPos() const { return mWindowPos; } const QPointF &screenPos() const { return mScreenPos; } - const QTouchDevice *device() const; + const QTouchDevice *device() const { return mDevice; } protected: Qt::NativeGestureType mGestureType; @@ -360,6 +362,7 @@ protected: qreal mRealValue; ulong mSequenceId; quint64 mIntValue; + const QTouchDevice *mDevice; }; #endif // QT_NO_GESTURES @@ -374,7 +377,7 @@ public: ~QKeyEvent(); int key() const { return k; } -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) bool matches(QKeySequence::StandardKey key) const; #endif Qt::KeyboardModifiers modifiers() const; @@ -750,18 +753,18 @@ private: }; #endif -#ifndef QT_NO_ACTION +#if QT_CONFIG(action) class Q_GUI_EXPORT QActionEvent : public QEvent { - QAction *act, *bef; + QGuiAction *act, *bef; public: - QActionEvent(int type, QAction *action, QAction *before = nullptr); + QActionEvent(int type, QGuiAction *action, QGuiAction *before = nullptr); ~QActionEvent(); - inline QAction *action() const { return act; } - inline QAction *before() const { return bef; } + inline QGuiAction *action() const { return act; } + inline QGuiAction *before() const { return bef; } }; -#endif +#endif // QT_CONFIG(action) class Q_GUI_EXPORT QFileOpenEvent : public QEvent { @@ -791,7 +794,7 @@ private: }; #endif -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) class Q_GUI_EXPORT QShortcutEvent : public QEvent { public: @@ -826,10 +829,10 @@ private: Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *); #endif -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);} inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);} -#endif // QT_NO_SHORTCUT +#endif // QT_CONFIG(shortcut) class Q_GUI_EXPORT QPointingDeviceUniqueId { @@ -854,14 +857,6 @@ private: }; Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE); -#if 0 -#pragma qt_sync_suspend_processing -#endif -template <> class QList<QPointingDeviceUniqueId> {}; // to prevent instantiation: use QVector instead -#if 0 -#pragma qt_sync_resume_processing -#endif - Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept; inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept { return !operator==(lhs, rhs); } diff --git a/src/gui/kernel/qguiaction.cpp b/src/gui/kernel/qguiaction.cpp new file mode 100644 index 0000000000..7c7d86f5ab --- /dev/null +++ b/src/gui/kernel/qguiaction.cpp @@ -0,0 +1,1214 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qguiaction.h" +#include "qguiactiongroup.h" + +#include "qguiaction_p.h" +#include "qguiapplication.h" +#include "qevent.h" +#include "qlist.h" +#include "qstylehints.h" +#if QT_CONFIG(shortcut) +# include <private/qshortcutmap_p.h> +#endif +#include <private/qguiapplication_p.h> +#include <private/qdebug_p.h> + +#define QAPP_CHECK(functionName) \ + if (Q_UNLIKELY(!QCoreApplication::instance())) { \ + qWarning("QAction: Initialize Q(Gui)Application before calling '" functionName "'."); \ + return; \ + } + +QT_BEGIN_NAMESPACE + +/* + internal: guesses a descriptive text from a text suited for a menu entry + */ +static QString qt_strippedText(QString s) +{ + s.remove(QLatin1String("...")); + for (int i = 0; i < s.size(); ++i) { + if (s.at(i) == QLatin1Char('&')) + s.remove(i, 1); + } + return s.trimmed(); +} + +QGuiActionPrivate::QGuiActionPrivate() : +#if QT_CONFIG(shortcut) + autorepeat(1), +#endif + enabled(1), forceDisabled(0), visible(1), forceInvisible(0), checkable(0), + checked(0), separator(0), fontSet(false), + iconVisibleInMenu(-1), shortcutVisibleInContextMenu(-1) +{ +} + +#if QT_CONFIG(shortcut) +static bool dummy(QObject *, Qt::ShortcutContext) { return false; } // only for GUI testing. + +QShortcutMap::ContextMatcher QGuiActionPrivate::contextMatcher() const +{ + return dummy; +} +#endif // QT_CONFIG(shortcut) + +QGuiActionPrivate::~QGuiActionPrivate() = default; + +void QGuiActionPrivate::sendDataChanged() +{ + Q_Q(QGuiAction); + QActionEvent e(QEvent::ActionChanged, q); + QCoreApplication::sendEvent(q, &e); + + emit q->changed(); +} + +#if QT_CONFIG(shortcut) +void QGuiActionPrivate::redoGrab(QShortcutMap &map) +{ + Q_Q(QGuiAction); + if (shortcutId) + map.removeShortcut(shortcutId, q); + if (shortcut.isEmpty()) + return; + shortcutId = map.addShortcut(q, shortcut, shortcutContext, contextMatcher()); + if (!enabled) + map.setShortcutEnabled(false, shortcutId, q); + if (!autorepeat) + map.setShortcutAutoRepeat(false, shortcutId, q); +} + +void QGuiActionPrivate::redoGrabAlternate(QShortcutMap &map) +{ + Q_Q(QGuiAction); + for(int i = 0; i < alternateShortcutIds.count(); ++i) { + if (const int id = alternateShortcutIds.at(i)) + map.removeShortcut(id, q); + } + alternateShortcutIds.clear(); + if (alternateShortcuts.isEmpty()) + return; + for(int i = 0; i < alternateShortcuts.count(); ++i) { + const QKeySequence& alternate = alternateShortcuts.at(i); + if (!alternate.isEmpty()) + alternateShortcutIds.append(map.addShortcut(q, alternate, shortcutContext, contextMatcher())); + else + alternateShortcutIds.append(0); + } + if (!enabled) { + for(int i = 0; i < alternateShortcutIds.count(); ++i) { + const int id = alternateShortcutIds.at(i); + map.setShortcutEnabled(false, id, q); + } + } + if (!autorepeat) { + for(int i = 0; i < alternateShortcutIds.count(); ++i) { + const int id = alternateShortcutIds.at(i); + map.setShortcutAutoRepeat(false, id, q); + } + } +} + +void QGuiActionPrivate::setShortcutEnabled(bool enable, QShortcutMap &map) +{ + Q_Q(QGuiAction); + if (shortcutId) + map.setShortcutEnabled(enable, shortcutId, q); + for(int i = 0; i < alternateShortcutIds.count(); ++i) { + if (const int id = alternateShortcutIds.at(i)) + map.setShortcutEnabled(enable, id, q); + } +} +#endif // QT_NO_SHORTCUT + + +/*! + \class QGuiAction + \brief QGuiAction is the base class for actions, an abstract user interface + action that can be inserted into widgets. + \since 6.0 + + \inmodule QtGui + + In applications many common commands can be invoked via menus, + toolbar buttons, and keyboard shortcuts. Since the user expects + each command to be performed in the same way, regardless of the + user interface used, it is useful to represent each command as + an \e action. + + Actions can be added to menus and toolbars, and will + automatically keep them in sync. For example, in a word processor, + if the user presses a Bold toolbar button, the Bold menu item + will automatically be checked. + + Actions can be created as independent objects, but they may + also be created during the construction of menus; the QMenu class + contains convenience functions for creating actions suitable for + use as menu items. + + A QGuiAction may contain an icon, menu text, a shortcut, status text, + "What's This?" text, and a tooltip. Most of these can be set in + the constructor. They can also be set independently with + setIcon(), setText(), setIconText(), setShortcut(), + setStatusTip(), setWhatsThis(), and setToolTip(). For menu items, + it is possible to set an individual font with setFont(). + + We recommend that actions are created as children of the window + they are used in. In most cases actions will be children of + the application's main window. + + \sa QMenu, QToolBar, {Application Example} +*/ + +/*! + \fn void QGuiAction::trigger() + + This is a convenience slot that calls activate(Trigger). +*/ + +/*! + \fn void QGuiAction::hover() + + This is a convenience slot that calls activate(Hover). +*/ + +/*! + \enum QGuiAction::MenuRole + + This enum describes how an action should be moved into the application menu on \macos. + + \value NoRole This action should not be put into the application menu + \value TextHeuristicRole This action should be put in the application menu based on the action's text + as described in the QMenuBar documentation. + \value ApplicationSpecificRole This action should be put in the application menu with an application specific role + \value AboutQtRole This action handles the "About Qt" menu item. + \value AboutRole This action should be placed where the "About" menu item is in the application menu. The text of + the menu item will be set to "About <application name>". The application name is fetched from the + \c{Info.plist} file in the application's bundle (See \l{Qt for macOS - Deployment}). + \value PreferencesRole This action should be placed where the "Preferences..." menu item is in the application menu. + \value QuitRole This action should be placed where the Quit menu item is in the application menu. + + Setting this value only has effect on items that are in the immediate menus + of the menubar, not the submenus of those menus. For example, if you have + File menu in your menubar and the File menu has a submenu, setting the + MenuRole for the actions in that submenu have no effect. They will never be moved. +*/ + +/*! + Constructs an action with \a parent. If \a parent is an action + group the action will be automatically inserted into the group. + + \note The \a parent argument is optional since Qt 5.7. +*/ +QGuiAction::QGuiAction(QObject *parent) + : QGuiAction(*new QGuiActionPrivate, parent) +{ +} + +/*! + Constructs an action with some \a text and \a parent. If \a + parent is an action group the action will be automatically + inserted into the group. + + The action uses a stripped version of \a text (e.g. "\&Menu + Option..." becomes "Menu Option") as descriptive text for + tool buttons. You can override this by setting a specific + description with setText(). The same text will be used for + tooltips unless you specify a different text using + setToolTip(). + +*/ +QGuiAction::QGuiAction(const QString &text, QObject *parent) + : QGuiAction(parent) +{ + Q_D(QGuiAction); + d->text = text; +} + +/*! + Constructs an action with an \a icon and some \a text and \a + parent. If \a parent is an action group the action will be + automatically inserted into the group. + + The action uses a stripped version of \a text (e.g. "\&Menu + Option..." becomes "Menu Option") as descriptive text for + tool buttons. You can override this by setting a specific + description with setText(). The same text will be used for + tooltips unless you specify a different text using + setToolTip(). +*/ +QGuiAction::QGuiAction(const QIcon &icon, const QString &text, QObject *parent) + : QGuiAction(text, parent) +{ + Q_D(QGuiAction); + d->icon = icon; +} + +/*! + \internal +*/ +QGuiAction::QGuiAction(QGuiActionPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ + Q_D(QGuiAction); + d->group = qobject_cast<QGuiActionGroup *>(parent); + if (d->group) + d->group->addAction(this); +} + +#if QT_CONFIG(shortcut) +/*! + \property QGuiAction::shortcut + \brief the action's primary shortcut key + + Valid keycodes for this property can be found in \l Qt::Key and + \l Qt::Modifier. There is no default shortcut key. +*/ +void QGuiAction::setShortcut(const QKeySequence &shortcut) +{ + QAPP_CHECK("setShortcut"); + + Q_D(QGuiAction); + if (d->shortcut == shortcut) + return; + + d->shortcut = shortcut; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); + d->sendDataChanged(); +} + +/*! + Sets \a shortcuts as the list of shortcuts that trigger the + action. The first element of the list is the primary shortcut. + + \sa shortcut +*/ +void QGuiAction::setShortcuts(const QList<QKeySequence> &shortcuts) +{ + Q_D(QGuiAction); + + QList <QKeySequence> listCopy = shortcuts; + + QKeySequence primary; + if (!listCopy.isEmpty()) + primary = listCopy.takeFirst(); + + if (d->shortcut == primary && d->alternateShortcuts == listCopy) + return; + + QAPP_CHECK("setShortcuts"); + + d->shortcut = primary; + d->alternateShortcuts = listCopy; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); + d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap); + d->sendDataChanged(); +} + +/*! + Sets a platform dependent list of shortcuts based on the \a key. + The result of calling this function will depend on the currently running platform. + Note that more than one shortcut can assigned by this action. + If only the primary shortcut is required, use setShortcut instead. + + \sa QKeySequence::keyBindings() +*/ +void QGuiAction::setShortcuts(QKeySequence::StandardKey key) +{ + QList <QKeySequence> list = QKeySequence::keyBindings(key); + setShortcuts(list); +} + +/*! + Returns the primary shortcut. + + \sa setShortcuts() +*/ +QKeySequence QGuiAction::shortcut() const +{ + Q_D(const QGuiAction); + return d->shortcut; +} + +/*! + Returns the list of shortcuts, with the primary shortcut as + the first element of the list. + + \sa setShortcuts() +*/ +QList<QKeySequence> QGuiAction::shortcuts() const +{ + Q_D(const QGuiAction); + QList <QKeySequence> shortcuts; + if (!d->shortcut.isEmpty()) + shortcuts << d->shortcut; + if (!d->alternateShortcuts.isEmpty()) + shortcuts << d->alternateShortcuts; + return shortcuts; +} + +/*! + \property QGuiAction::shortcutContext + \brief the context for the action's shortcut + + Valid values for this property can be found in \l Qt::ShortcutContext. + The default value is Qt::WindowShortcut. +*/ +void QGuiAction::setShortcutContext(Qt::ShortcutContext context) +{ + Q_D(QGuiAction); + if (d->shortcutContext == context) + return; + QAPP_CHECK("setShortcutContext"); + d->shortcutContext = context; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); + d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap); + d->sendDataChanged(); +} + +Qt::ShortcutContext QGuiAction::shortcutContext() const +{ + Q_D(const QGuiAction); + return d->shortcutContext; +} + +/*! + \property QGuiAction::autoRepeat + \brief whether the action can auto repeat + + If true, the action will auto repeat when the keyboard shortcut + combination is held down, provided that keyboard auto repeat is + enabled on the system. + The default value is true. +*/ +void QGuiAction::setAutoRepeat(bool on) +{ + Q_D(QGuiAction); + if (d->autorepeat == on) + return; + QAPP_CHECK("setAutoRepeat"); + d->autorepeat = on; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); + d->redoGrabAlternate(QGuiApplicationPrivate::instance()->shortcutMap); + d->sendDataChanged(); +} + +bool QGuiAction::autoRepeat() const +{ + Q_D(const QGuiAction); + return d->autorepeat; +} +#endif // QT_CONFIG(shortcut) + +/*! + \property QGuiAction::font + \brief the action's font + + The font property is used to render the text set on the + QAction. The font will can be considered a hint as it will not be + consulted in all cases based upon application and style. + + By default, this property contains the application's default font. + + \sa setText() +*/ +void QGuiAction::setFont(const QFont &font) +{ + Q_D(QGuiAction); + if (d->font == font) + return; + + d->fontSet = true; + d->font = font; + d->sendDataChanged(); +} + +QFont QGuiAction::font() const +{ + Q_D(const QGuiAction); + return d->font; +} + + +/*! + Destroys the object and frees allocated resources. +*/ +QGuiAction::~QGuiAction() +{ + Q_D(QGuiAction); + if (d->group) + d->group->removeAction(this); +#if QT_CONFIG(shortcut) + if (d->shortcutId && qApp) { + QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->shortcutId, this); + for (int id : qAsConst(d->alternateShortcutIds)) + QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(id, this); + } +#endif +} + +/*! + Sets this action group to \a group. The action will be automatically + added to the group's list of actions. + + Actions within the group will be mutually exclusive. + + \sa QGuiActionGroup, guiActionGroup() +*/ +void QGuiAction::setActionGroup(QGuiActionGroup *group) +{ + Q_D(QGuiAction); + if(group == d->group) + return; + + if(d->group) + d->group->removeAction(this); + d->group = group; + if(group) + group->addAction(this); + d->sendDataChanged(); +} + +/*! + Returns the action group for this action. If no action group manages + this action, then \nullptr will be returned. + + \sa QGuiActionGroup, setActionGroup() +*/ +QGuiActionGroup *QGuiAction::guiActionGroup() const +{ + Q_D(const QGuiAction); + return d->group; +} + + +/*! + \property QGuiAction::icon + \brief the action's icon + + In toolbars, the icon is used as the tool button icon; in menus, + it is displayed to the left of the menu text. There is no default + icon. + + If a null icon (QIcon::isNull()) is passed into this function, + the icon of the action is cleared. +*/ +void QGuiAction::setIcon(const QIcon &icon) +{ + Q_D(QGuiAction); + d->icon = icon; + d->sendDataChanged(); +} + +QIcon QGuiAction::icon() const +{ + Q_D(const QGuiAction); + return d->icon; +} + +/*! + If \a b is true then this action will be considered a separator. + + How a separator is represented depends on the widget it is inserted + into. Under most circumstances the text, submenu, and icon will be + ignored for separator actions. + + \sa isSeparator() +*/ +void QGuiAction::setSeparator(bool b) +{ + Q_D(QGuiAction); + if (d->separator == b) + return; + + d->separator = b; + d->sendDataChanged(); +} + +/*! + Returns \c true if this action is a separator action; otherwise it + returns \c false. + + \sa setSeparator() +*/ +bool QGuiAction::isSeparator() const +{ + Q_D(const QGuiAction); + return d->separator; +} + +/*! + \property QGuiAction::text + \brief the action's descriptive text + + If the action is added to a menu, the menu option will consist of + the icon (if there is one), the text, and the shortcut (if there + is one). If the text is not explicitly set in the constructor, or + by using setText(), the action's description icon text will be + used as text. There is no default text. + + \sa iconText +*/ +void QGuiAction::setText(const QString &text) +{ + Q_D(QGuiAction); + if (d->text == text) + return; + + d->text = text; + d->sendDataChanged(); +} + +QString QGuiAction::text() const +{ + Q_D(const QGuiAction); + QString s = d->text; + if(s.isEmpty()) { + s = d->iconText; + s.replace(QLatin1Char('&'), QLatin1String("&&")); + } + return s; +} + +/*! + \property QGuiAction::iconText + \brief the action's descriptive icon text + + If QToolBar::toolButtonStyle is set to a value that permits text to + be displayed, the text defined held in this property appears as a + label in the relevant tool button. + + It also serves as the default text in menus and tooltips if the action + has not been defined with setText() or setToolTip(), and will + also be used in toolbar buttons if no icon has been defined using setIcon(). + + If the icon text is not explicitly set, the action's normal text will be + used for the icon text. + + By default, this property contains an empty string. + + \sa setToolTip(), setStatusTip() +*/ +void QGuiAction::setIconText(const QString &text) +{ + Q_D(QGuiAction); + if (d->iconText == text) + return; + + d->iconText = text; + d->sendDataChanged(); +} + +QString QGuiAction::iconText() const +{ + Q_D(const QGuiAction); + if (d->iconText.isEmpty()) + return qt_strippedText(d->text); + return d->iconText; +} + +/*! + \property QGuiAction::toolTip + \brief the action's tooltip + + This text is used for the tooltip. If no tooltip is specified, + the action's text is used. + + By default, this property contains the action's text. + + \sa setStatusTip(), setShortcut() +*/ +void QGuiAction::setToolTip(const QString &tooltip) +{ + Q_D(QGuiAction); + if (d->tooltip == tooltip) + return; + + d->tooltip = tooltip; + d->sendDataChanged(); +} + +QString QGuiAction::toolTip() const +{ + Q_D(const QGuiAction); + if (d->tooltip.isEmpty()) { + if (!d->text.isEmpty()) + return qt_strippedText(d->text); + return qt_strippedText(d->iconText); + } + return d->tooltip; +} + +/*! + \property QGuiAction::statusTip + \brief the action's status tip + + The status tip is displayed on all status bars provided by the + action's top-level parent widget. + + By default, this property contains an empty string. + + \sa setToolTip(), showStatusText() +*/ +void QGuiAction::setStatusTip(const QString &statustip) +{ + Q_D(QGuiAction); + if (d->statustip == statustip) + return; + + d->statustip = statustip; + d->sendDataChanged(); +} + +QString QGuiAction::statusTip() const +{ + Q_D(const QGuiAction); + return d->statustip; +} + +/*! + \property QGuiAction::whatsThis + \brief the action's "What's This?" help text + + The "What's This?" text is used to provide a brief description of + the action. The text may contain rich text. There is no default + "What's This?" text. + + \sa QWhatsThis +*/ +void QGuiAction::setWhatsThis(const QString &whatsthis) +{ + Q_D(QGuiAction); + if (d->whatsthis == whatsthis) + return; + + d->whatsthis = whatsthis; + d->sendDataChanged(); +} + +QString QGuiAction::whatsThis() const +{ + Q_D(const QGuiAction); + return d->whatsthis; +} + +/*! + \enum QGuiAction::Priority + + This enum defines priorities for actions in user interface. + + \value LowPriority The action should not be prioritized in + the user interface. + + \value NormalPriority + + \value HighPriority The action should be prioritized in + the user interface. + + \sa priority +*/ + + +/*! + \property QGuiAction::priority + + \brief the actions's priority in the user interface. + + This property can be set to indicate how the action should be prioritized + in the user interface. + + For instance, when toolbars have the Qt::ToolButtonTextBesideIcon + mode set, then actions with LowPriority will not show the text + labels. +*/ +void QGuiAction::setPriority(Priority priority) +{ + Q_D(QGuiAction); + if (d->priority == priority) + return; + + d->priority = priority; + d->sendDataChanged(); +} + +QGuiAction::Priority QGuiAction::priority() const +{ + Q_D(const QGuiAction); + return d->priority; +} + +/*! + \property QGuiAction::checkable + \brief whether the action is a checkable action + + A checkable action is one which has an on/off state. For example, + in a word processor, a Bold toolbar button may be either on or + off. An action which is not a toggle action is a command action; + a command action is simply executed, e.g. file save. + By default, this property is \c false. + + In some situations, the state of one toggle action should depend + on the state of others. For example, "Left Align", "Center" and + "Right Align" toggle actions are mutually exclusive. To achieve + exclusive toggling, add the relevant toggle actions to a + QGuiActionGroup with the QGuiActionGroup::exclusive property set to + true. + + \sa setChecked() +*/ +void QGuiAction::setCheckable(bool b) +{ + Q_D(QGuiAction); + if (d->checkable == b) + return; + + d->checkable = b; + d->checked = false; + d->sendDataChanged(); +} + +bool QGuiAction::isCheckable() const +{ + Q_D(const QGuiAction); + return d->checkable; +} + +/*! + \fn void QGuiAction::toggle() + + This is a convenience function for the \l checked property. + Connect to it to change the checked state to its opposite state. +*/ +void QGuiAction::toggle() +{ + Q_D(QGuiAction); + setChecked(!d->checked); +} + +/*! + \property QGuiAction::checked + \brief whether the action is checked. + + Only checkable actions can be checked. By default, this is false + (the action is unchecked). + + \note The notifier signal for this property is toggled(). As toggling + a QAction changes its state, it will also emit a changed() signal. + + \sa checkable, toggled() +*/ +void QGuiAction::setChecked(bool b) +{ + Q_D(QGuiAction); + if (!d->checkable || d->checked == b) + return; + + QPointer<QGuiAction> guard(this); + d->checked = b; + d->sendDataChanged(); + if (guard) + emit toggled(b); +} + +bool QGuiAction::isChecked() const +{ + Q_D(const QGuiAction); + return d->checked; +} + +/*! + \fn void QGuiAction::setDisabled(bool b) + + This is a convenience function for the \l enabled property, that + is useful for signals--slots connections. If \a b is true the + action is disabled; otherwise it is enabled. +*/ + +/*! + \property QGuiAction::enabled + \brief whether the action is enabled + + Disabled actions cannot be chosen by the user. They do not + disappear from menus or toolbars, but they are displayed in a way + which indicates that they are unavailable. For example, they might + be displayed using only shades of gray. + + \uicontrol{What's This?} help on disabled actions is still available, provided + that the QAction::whatsThis property is set. + + An action will be disabled when all widgets to which it is added + (with QWidget::addAction()) are disabled or not visible. When an + action is disabled, it is not possible to trigger it through its + shortcut. + + By default, this property is \c true (actions are enabled). + + \sa text +*/ +void QGuiAction::setEnabled(bool b) +{ + Q_D(QGuiAction); + if (b == d->enabled && b != d->forceDisabled) + return; + d->forceDisabled = !b; + if (b && (!d->visible || (d->group && !d->group->isEnabled()))) + return; + QAPP_CHECK("setEnabled"); + d->enabled = b; +#if QT_CONFIG(shortcut) + d->setShortcutEnabled(b, QGuiApplicationPrivate::instance()->shortcutMap); +#endif + d->sendDataChanged(); +} + +bool QGuiAction::isEnabled() const +{ + Q_D(const QGuiAction); + return d->enabled; +} + +/*! + \property QGuiAction::visible + \brief whether the action can be seen (e.g. in menus and toolbars) + + If \e visible is true the action can be seen (e.g. in menus and + toolbars) and chosen by the user; if \e visible is false the + action cannot be seen or chosen by the user. + + Actions which are not visible are \e not grayed out; they do not + appear at all. + + By default, this property is \c true (actions are visible). +*/ +void QGuiAction::setVisible(bool b) +{ + Q_D(QGuiAction); + if (b == d->visible && b != d->forceInvisible) + return; + QAPP_CHECK("setVisible"); + d->forceInvisible = !b; + d->visible = b; + d->enabled = b && !d->forceDisabled && (!d->group || d->group->isEnabled()) ; +#if QT_CONFIG(shortcut) + d->setShortcutEnabled(d->enabled, QGuiApplicationPrivate::instance()->shortcutMap); +#endif + d->sendDataChanged(); +} + + +bool QGuiAction::isVisible() const +{ + Q_D(const QGuiAction); + return d->visible; +} + +/*! + \reimp +*/ +bool QGuiAction::event(QEvent *e) +{ +#if QT_CONFIG(shortcut) + if (e->type() == QEvent::Shortcut) { + QShortcutEvent *se = static_cast<QShortcutEvent *>(e); + Q_ASSERT_X(se->key() == d_func()->shortcut || d_func()->alternateShortcuts.contains(se->key()), + "QAction::event", + "Received shortcut event from incorrect shortcut"); + if (se->isAmbiguous()) + qWarning("QAction::event: Ambiguous shortcut overload: %s", se->key().toString(QKeySequence::NativeText).toLatin1().constData()); + else + activate(Trigger); + return true; + } +#endif // QT_CONFIG(shortcut) + return QObject::event(e); +} + +/*! + Returns the user data as set in QAction::setData. + + \sa setData() +*/ +QVariant QGuiAction::data() const +{ + Q_D(const QGuiAction); + return d->userData; +} + +/*! + Sets the action's internal data to the given \a userData. + + \sa data() +*/ +void QGuiAction::setData(const QVariant &data) +{ + Q_D(QGuiAction); + if (d->userData == data) + return; + d->userData = data; + d->sendDataChanged(); +} + +/*! + Sends the relevant signals for ActionEvent \a event. + + Action based widgets use this API to cause the QAction + to emit signals as well as emitting their own. +*/ +void QGuiAction::activate(ActionEvent event) +{ + Q_D(QGuiAction); + if(event == Trigger) { + QPointer<QObject> guard = this; + if(d->checkable) { + // the checked action of an exclusive group may not be unchecked + if (d->checked && (d->group + && d->group->exclusionPolicy() == QGuiActionGroup::ExclusionPolicy::Exclusive + && d->group->checkedGuiAction() == this)) { + if (!guard.isNull()) + emit triggered(true); + return; + } + setChecked(!d->checked); + } + if (!guard.isNull()) + emit triggered(d->checked); + } else if(event == Hover) { + emit hovered(); + } +} + +/*! + \fn void QGuiAction::triggered(bool checked) + + This signal is emitted when an action is activated by the user; + for example, when the user clicks a menu option, toolbar button, + or presses an action's shortcut key combination, or when trigger() + was called. Notably, it is \e not emitted when setChecked() or + toggle() is called. + + If the action is checkable, \a checked is true if the action is + checked, or false if the action is unchecked. + + \sa activate(), toggled(), checked +*/ + +/*! + \fn void QGuiAction::toggled(bool checked) + + This signal is emitted whenever a checkable action changes its + isChecked() status. This can be the result of a user interaction, + or because setChecked() was called. As setChecked() changes the + QAction, it emits changed() in addition to toggled(). + + \a checked is true if the action is checked, or false if the + action is unchecked. + + \sa activate(), triggered(), checked +*/ + +/*! + \fn void QGuiAction::hovered() + + This signal is emitted when an action is highlighted by the user; + for example, when the user pauses with the cursor over a menu option, + toolbar button, or presses an action's shortcut key combination. + + \sa activate() +*/ + +/*! + \fn void QGuiAction::changed() + + This signal is emitted when an action has changed. If you + are only interested in actions in a given widget, you can + watch for QWidget::actionEvent() sent with an + QEvent::ActionChanged. + + \sa QWidget::actionEvent() +*/ + +/*! + \enum QGuiAction::ActionEvent + + This enum type is used when calling QAction::activate() + + \value Trigger this will cause the QAction::triggered() signal to be emitted. + + \value Hover this will cause the QAction::hovered() signal to be emitted. +*/ + +/*! + \property QGuiAction::menuRole + \brief the action's menu role + + This indicates what role the action serves in the application menu on + \macos. By default all actions have the TextHeuristicRole, which means that + the action is added based on its text (see QMenuBar for more information). + + The menu role can only be changed before the actions are put into the menu + bar in \macos (usually just before the first application window is + shown). +*/ +void QGuiAction::setMenuRole(MenuRole menuRole) +{ + Q_D(QGuiAction); + if (d->menuRole == menuRole) + return; + + d->menuRole = menuRole; + d->sendDataChanged(); +} + +QGuiAction::MenuRole QGuiAction::menuRole() const +{ + Q_D(const QGuiAction); + return d->menuRole; +} + +/*! + \property QGuiAction::iconVisibleInMenu + \brief Whether or not an action should show an icon in a menu + + In some applications, it may make sense to have actions with icons in the + toolbar, but not in menus. If true, the icon (if valid) is shown in the menu, when it + is false, it is not shown. + + The default is to follow whether the Qt::AA_DontShowIconsInMenus attribute + is set for the application. Explicitly settings this property overrides + the presence (or abscence) of the attribute. + + For example: + \snippet code/src_gui_kernel_qaction.cpp 0 + + \sa icon, QCoreApplication::setAttribute() +*/ +void QGuiAction::setIconVisibleInMenu(bool visible) +{ + Q_D(QGuiAction); + if (d->iconVisibleInMenu == -1 || visible != bool(d->iconVisibleInMenu)) { + int oldValue = d->iconVisibleInMenu; + d->iconVisibleInMenu = visible; + // Only send data changed if we really need to. + if (oldValue != -1 + || visible == !QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus)) { + d->sendDataChanged(); + } + } +} + +bool QGuiAction::isIconVisibleInMenu() const +{ + Q_D(const QGuiAction); + if (d->iconVisibleInMenu == -1) { + return !QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus); + } + return d->iconVisibleInMenu; +} + +/*! + \property QGuiAction::shortcutVisibleInContextMenu + \brief Whether or not an action should show a shortcut in a context menu + + In some applications, it may make sense to have actions with shortcuts in + context menus. If true, the shortcut (if valid) is shown when the action is + shown via a context menu, when it is false, it is not shown. + + The default is to follow whether the Qt::AA_DontShowShortcutsInContextMenus attribute + is set for the application, falling back to the widget style hint. + Explicitly setting this property overrides the presence (or abscence) of the attribute. + + \sa shortcut, QCoreApplication::setAttribute() +*/ +void QGuiAction::setShortcutVisibleInContextMenu(bool visible) +{ + Q_D(QGuiAction); + if (d->shortcutVisibleInContextMenu == -1 || visible != bool(d->shortcutVisibleInContextMenu)) { + int oldValue = d->shortcutVisibleInContextMenu; + d->shortcutVisibleInContextMenu = visible; + // Only send data changed if we really need to. + if (oldValue != -1 + || visible == !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus)) { + d->sendDataChanged(); + } + } +} + +bool QGuiAction::isShortcutVisibleInContextMenu() const +{ + Q_D(const QGuiAction); + if (d->shortcutVisibleInContextMenu == -1) { + return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) + && QGuiApplication::styleHints()->showShortcutsInContextMenus(); + } + return d->shortcutVisibleInContextMenu; +} + +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug d, const QGuiAction *action) +{ + QDebugStateSaver saver(d); + d.nospace(); + d << "QAction(" << static_cast<const void *>(action); + if (action) { + d << " text=" << action->text(); + if (!action->toolTip().isEmpty()) + d << " toolTip=" << action->toolTip(); + if (action->isCheckable()) + d << " checked=" << action->isChecked(); +#if QT_CONFIG(shortcut) + if (!action->shortcut().isEmpty()) + d << " shortcut=" << action->shortcut(); +#endif + d << " menuRole="; + QtDebugUtils::formatQEnum(d, action->menuRole()); + d << " visible=" << action->isVisible(); + } else { + d << '0'; + } + d << ')'; + return d; +} +#endif // QT_NO_DEBUG_STREAM + +QT_END_NAMESPACE + +#include "moc_qguiaction.cpp" diff --git a/src/gui/kernel/qguiaction.h b/src/gui/kernel/qguiaction.h new file mode 100644 index 0000000000..454f66893f --- /dev/null +++ b/src/gui/kernel/qguiaction.h @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGUIACTION_H +#define QGUIACTION_H + +#include <QtGui/qtguiglobal.h> +#if QT_CONFIG(shortcut) +# include <QtGui/qkeysequence.h> +#endif +#include <QtGui/qicon.h> +#include <QtCore/qstring.h> +#include <QtCore/qvariant.h> + +QT_REQUIRE_CONFIG(action); + +QT_BEGIN_NAMESPACE + +class QActionEvent; +class QGuiActionGroup; +class QGuiActionPrivate; + +class Q_GUI_EXPORT QGuiAction : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QGuiAction) + + Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed) + Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed) + Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed) + Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed) + Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed) + Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed) + Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed) + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) +#if QT_CONFIG(shortcut) + Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed) + Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed) + Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed) +#endif // QT_CONFIG(shortcut) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed) + Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed) + Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed) + Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu WRITE setShortcutVisibleInContextMenu NOTIFY changed) + Q_PROPERTY(Priority priority READ priority WRITE setPriority) + +public: + // note this is copied into qplatformmenu.h, which must stay in sync + enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole, + AboutRole, PreferencesRole, QuitRole }; + Q_ENUM(MenuRole) + enum Priority { LowPriority = 0, + NormalPriority = 128, + HighPriority = 256}; + Q_ENUM(Priority) + explicit QGuiAction(QObject *parent = nullptr); + explicit QGuiAction(const QString &text, QObject *parent = nullptr); + explicit QGuiAction(const QIcon &icon, const QString &text, QObject *parent = nullptr); + + ~QGuiAction(); + + void setActionGroup(QGuiActionGroup *group); + QGuiActionGroup *guiActionGroup() const; + void setIcon(const QIcon &icon); + QIcon icon() const; + + void setText(const QString &text); + QString text() const; + + void setIconText(const QString &text); + QString iconText() const; + + void setToolTip(const QString &tip); + QString toolTip() const; + + void setStatusTip(const QString &statusTip); + QString statusTip() const; + + void setWhatsThis(const QString &what); + QString whatsThis() const; + + void setPriority(Priority priority); + Priority priority() const; + + void setSeparator(bool b); + bool isSeparator() const; + +#if QT_CONFIG(shortcut) + void setShortcut(const QKeySequence &shortcut); + QKeySequence shortcut() const; + + void setShortcuts(const QList<QKeySequence> &shortcuts); + void setShortcuts(QKeySequence::StandardKey); + QList<QKeySequence> shortcuts() const; + + void setShortcutContext(Qt::ShortcutContext context); + Qt::ShortcutContext shortcutContext() const; + + void setAutoRepeat(bool); + bool autoRepeat() const; +#endif // QT_CONFIG(shortcut) + + void setFont(const QFont &font); + QFont font() const; + + void setCheckable(bool); + bool isCheckable() const; + + QVariant data() const; + void setData(const QVariant &var); + + bool isChecked() const; + + bool isEnabled() const; + + bool isVisible() const; + + enum ActionEvent { Trigger, Hover }; + void activate(ActionEvent event); + + void setMenuRole(MenuRole menuRole); + MenuRole menuRole() const; + + void setIconVisibleInMenu(bool visible); + bool isIconVisibleInMenu() const; + + void setShortcutVisibleInContextMenu(bool show); + bool isShortcutVisibleInContextMenu() const; + +protected: + bool event(QEvent *) override; + QGuiAction(QGuiActionPrivate &dd, QObject *parent); + +public Q_SLOTS: + void trigger() { activate(Trigger); } + void hover() { activate(Hover); } + void setChecked(bool); + void toggle(); + void setEnabled(bool); + inline void setDisabled(bool b) { setEnabled(!b); } + void setVisible(bool); + +Q_SIGNALS: + void changed(); + void triggered(bool checked = false); + void hovered(); + void toggled(bool); + +private: + Q_DISABLE_COPY(QGuiAction) + friend class QGuiActionGroup; +}; + +#ifndef QT_NO_DEBUG_STREAM +Q_GUI_EXPORT QDebug operator<<(QDebug, const QGuiAction *); +#endif + +QT_END_NAMESPACE + +#endif // QGUIACTION_H diff --git a/src/gui/kernel/qguiaction_p.h b/src/gui/kernel/qguiaction_p.h new file mode 100644 index 0000000000..3358ed1070 --- /dev/null +++ b/src/gui/kernel/qguiaction_p.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGUIACTION_P_H +#define QGUIACTION_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtGui/private/qtguiglobal_p.h> +#include <QtGui/qguiaction.h> +#include <QtGui/qfont.h> +#if QT_CONFIG(shortcut) +# include <QtGui/private/qshortcutmap_p.h> +#endif +#include "private/qobject_p.h" + +QT_REQUIRE_CONFIG(action); + +QT_BEGIN_NAMESPACE + +class QShortcutMap; + +class Q_GUI_EXPORT QGuiActionPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QGuiAction) +public: + QGuiActionPrivate(); + ~QGuiActionPrivate(); + +#if QT_CONFIG(shortcut) + virtual QShortcutMap::ContextMatcher contextMatcher() const; +#endif + + static QGuiActionPrivate *get(QGuiAction *q) + { + return q->d_func(); + } + + + QPointer<QGuiActionGroup> group; + QString text; + QString iconText; + QIcon icon; + QString tooltip; + QString statustip; + QString whatsthis; +#if QT_CONFIG(shortcut) + QKeySequence shortcut; + QList<QKeySequence> alternateShortcuts; +#endif + QVariant userData; +#if QT_CONFIG(shortcut) + int shortcutId = 0; + QVector<int> alternateShortcutIds; + Qt::ShortcutContext shortcutContext = Qt::WindowShortcut; + uint autorepeat : 1; +#endif + QFont font; + uint enabled : 1, forceDisabled : 1; + uint visible : 1, forceInvisible : 1; + uint checkable : 1; + uint checked : 1; + uint separator : 1; + uint fontSet : 1; + + int iconVisibleInMenu : 2; // Only has values -1, 0, and 1 + int shortcutVisibleInContextMenu : 2; // Only has values -1, 0, and 1 + + QGuiAction::MenuRole menuRole = QGuiAction::TextHeuristicRole; + QGuiAction::Priority priority = QGuiAction::NormalPriority; + +#if QT_CONFIG(shortcut) + void redoGrab(QShortcutMap &map); + void redoGrabAlternate(QShortcutMap &map); + void setShortcutEnabled(bool enable, QShortcutMap &map); +#endif // QT_NO_SHORTCUT + + void sendDataChanged(); +}; + +QT_END_NAMESPACE + +#endif // QACTION_P_H diff --git a/src/gui/kernel/qguiactiongroup.cpp b/src/gui/kernel/qguiactiongroup.cpp new file mode 100644 index 0000000000..82f5e0a0af --- /dev/null +++ b/src/gui/kernel/qguiactiongroup.cpp @@ -0,0 +1,345 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qguiactiongroup.h" + +#include "qguiaction.h" +#include "qguiaction_p.h" +#include "qguiactiongroup_p.h" +#include "qevent.h" +#include "qlist.h" + +QT_BEGIN_NAMESPACE + +QGuiActionGroupPrivate::QGuiActionGroupPrivate() : + enabled(1), visible(1) +{ +} + +QGuiActionGroupPrivate::~QGuiActionGroupPrivate() = default; + +void QGuiActionGroup::_q_actionChanged() +{ + Q_D(QGuiActionGroup); + auto action = qobject_cast<QGuiAction*>(sender()); + Q_ASSERT_X(action != nullptr, "QGuiActionGroup::_q_actionChanged", "internal error"); + if (d->exclusionPolicy != QGuiActionGroup::ExclusionPolicy::None) { + if (action->isChecked()) { + if (action != d->current) { + if (!d->current.isNull()) + d->current->setChecked(false); + d->current = action; + } + } else if (action == d->current) { + d->current = nullptr; + } + } +} + +void QGuiActionGroup::_q_actionTriggered() +{ + Q_D(QGuiActionGroup); + auto action = qobject_cast<QGuiAction*>(sender()); + Q_ASSERT_X(action != nullptr, "QGuiActionGroup::_q_actionTriggered", "internal error"); + d->emitSignal(QGuiActionGroupPrivate::Triggered, action); +} + +void QGuiActionGroup::_q_actionHovered() +{ + Q_D(QGuiActionGroup); + auto action = qobject_cast<QGuiAction*>(sender()); + Q_ASSERT_X(action != nullptr, "QGuiActionGroup::_q_actionHovered", "internal error"); + d->emitSignal(QGuiActionGroupPrivate::Hovered, action); +} + +/*! + \class QGuiActionGroup + \brief The QGuiActionGroup class groups actions together. + \since 6.0 + + \inmodule QtGui + + QGuiActionGroup is a base class for classes grouping + classes inhheriting QGuiAction objects together. + + In some situations it is useful to group QGuiAction objects together. + For example, if you have a \uicontrol{Left Align} action, a \uicontrol{Right + Align} action, a \uicontrol{Justify} action, and a \uicontrol{Center} action, + only one of these actions should be active at any one time. One + simple way of achieving this is to group the actions together in + an action group, inheriting QGuiActionGroup. + + \sa QGuiAction +*/ + +/*! + \enum QGuiActionGroup::ExclusionPolicy + + This enum specifies the different policies that can be used to + control how the group performs exclusive checking on checkable actions. + + \value None + The actions in the group can be checked independently of each other. + + \value Exclusive + Exactly one action can be checked at any one time. + This is the default policy. + + \value ExclusiveOptional + At most one action can be checked at any one time. The actions + can also be all unchecked. + + \sa exclusionPolicy +*/ + +/*! + Constructs an action group for the \a parent object. + + The action group is exclusive by default. Call setExclusive(false) + to make the action group non-exclusive. To make the group exclusive + but allow unchecking the active action call instead + setExclusionPolicy(QGuiActionGroup::ExclusionPolicy::ExclusiveOptional) +*/ +QGuiActionGroup::QGuiActionGroup(QObject* parent) : + QGuiActionGroup(*new QGuiActionGroupPrivate, parent) +{ +} + +QGuiActionGroup::QGuiActionGroup(QGuiActionGroupPrivate &dd, QObject *parent) : + QObject(dd, parent) +{ +} + +/*! + Destroys the action group. +*/ +QGuiActionGroup::~QGuiActionGroup() = default; + +/*! + \fn QGuiAction *QGuiActionGroup::addAction(QGuiAction *action) + + Adds the \a action to this group, and returns it. + + Normally an action is added to a group by creating it with the + group as its parent, so this function is not usually used. + + \sa QGuiAction::setActionGroup() +*/ +QGuiAction *QGuiActionGroup::addAction(QGuiAction* a) +{ + Q_D(QGuiActionGroup); + if (!d->actions.contains(a)) { + d->actions.append(a); + QObject::connect(a, &QGuiAction::triggered, this, &QGuiActionGroup::_q_actionTriggered); + QObject::connect(a, &QGuiAction::changed, this, &QGuiActionGroup::_q_actionChanged); + QObject::connect(a, &QGuiAction::hovered, this, &QGuiActionGroup::_q_actionHovered); + } + if (!a->d_func()->forceDisabled) { + a->setEnabled(d->enabled); + a->d_func()->forceDisabled = false; + } + if (!a->d_func()->forceInvisible) { + a->setVisible(d->visible); + a->d_func()->forceInvisible = false; + } + if (a->isChecked()) + d->current = a; + QGuiActionGroup *oldGroup = a->d_func()->group; + if (oldGroup != this) { + if (oldGroup) + oldGroup->removeAction(a); + a->d_func()->group = this; + a->d_func()->sendDataChanged(); + } + return a; +} + +/*! + Removes the \a action from this group. The action will have no + parent as a result. + + \sa QGuiAction::setActionGroup() +*/ +void QGuiActionGroup::removeAction(QGuiAction *action) +{ + Q_D(QGuiActionGroup); + if (d->actions.removeAll(action)) { + if (action == d->current) + d->current = nullptr; + QObject::disconnect(action, &QGuiAction::triggered, this, &QGuiActionGroup::_q_actionTriggered); + QObject::disconnect(action, &QGuiAction::changed, this, &QGuiActionGroup::_q_actionChanged); + QObject::disconnect(action, &QGuiAction::hovered, this, &QGuiActionGroup::_q_actionHovered); + action->d_func()->group = nullptr; + } +} + +/*! + Returns the list of this groups's actions. This may be empty. +*/ +QList<QGuiAction*> QGuiActionGroup::guiActions() const +{ + Q_D(const QGuiActionGroup); + return d->actions; +} + +/*! + \brief Enable or disable the group exclusion checking + + This is a convenience method that calls + setExclusionPolicy(ExclusionPolicy::Exclusive). + + \sa QGuiActionGroup::exclusionPolicy +*/ +void QGuiActionGroup::setExclusive(bool b) +{ + setExclusionPolicy(b ? QGuiActionGroup::ExclusionPolicy::Exclusive + : QGuiActionGroup::ExclusionPolicy::None); +} + +/*! + \brief Returs true if the group is exclusive + + The group is exclusive if the ExclusionPolicy is either Exclusive + or ExclusionOptional. + +*/ +bool QGuiActionGroup::isExclusive() const +{ + return exclusionPolicy() != QGuiActionGroup::ExclusionPolicy::None; +} + +/*! + \property QGuiActionGroup::exclusionPolicy + \brief This property holds the group exclusive checking policy + + If exclusionPolicy is set to Exclusive, only one checkable + action in the action group can ever be active at any time. If the user + chooses another checkable action in the group, the one they chose becomes + active and the one that was active becomes inactive. If exclusionPolicy is + set to ExclusionOptional the group is exclusive but the active checkable + action in the group can be unchecked leaving the group with no actions + checked. + + \sa QGuiAction::checkable +*/ +void QGuiActionGroup::setExclusionPolicy(QGuiActionGroup::ExclusionPolicy policy) +{ + Q_D(QGuiActionGroup); + d->exclusionPolicy = policy; +} + +QGuiActionGroup::ExclusionPolicy QGuiActionGroup::exclusionPolicy() const +{ + Q_D(const QGuiActionGroup); + return d->exclusionPolicy; +} + +/*! + \fn void QGuiActionGroup::setDisabled(bool b) + + This is a convenience function for the \l enabled property, that + is useful for signals--slots connections. If \a b is true the + action group is disabled; otherwise it is enabled. +*/ + +/*! + \property QGuiActionGroup::enabled + \brief whether the action group is enabled + + Each action in the group will be enabled or disabled unless it + has been explicitly disabled. + + \sa QGuiAction::setEnabled() +*/ +void QGuiActionGroup::setEnabled(bool b) +{ + Q_D(QGuiActionGroup); + d->enabled = b; + for (auto action : qAsConst(d->actions)) { + if (!action->d_func()->forceDisabled) { + action->setEnabled(b); + action->d_func()->forceDisabled = false; + } + } +} + +bool QGuiActionGroup::isEnabled() const +{ + Q_D(const QGuiActionGroup); + return d->enabled; +} + +/*! + Returns the currently checked action in the group, or \nullptr if + none are checked. +*/ +QGuiAction *QGuiActionGroup::checkedGuiAction() const +{ + Q_D(const QGuiActionGroup); + return d->current.data(); +} + +/*! + \property QGuiActionGroup::visible + \brief whether the action group is visible + + Each action in the action group will match the visible state of + this group unless it has been explicitly hidden. + + \sa QGuiAction::setEnabled() +*/ +void QGuiActionGroup::setVisible(bool b) +{ + Q_D(QGuiActionGroup); + d->visible = b; + for (auto action : qAsConst(d->actions)) { + if (!action->d_func()->forceInvisible) { + action->setVisible(b); + action->d_func()->forceInvisible = false; + } + } +} + +bool QGuiActionGroup::isVisible() const +{ + Q_D(const QGuiActionGroup); + return d->visible; +} + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qguiactiongroup.h b/src/gui/kernel/qguiactiongroup.h new file mode 100644 index 0000000000..ef08fb2e04 --- /dev/null +++ b/src/gui/kernel/qguiactiongroup.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGUIACTIONGROUP_H +#define QGUIACTIONGROUP_H + +#include <QtGui/qtguiglobal.h> +#include <QtGui/qguiaction.h> + +QT_REQUIRE_CONFIG(action); + +QT_BEGIN_NAMESPACE + +class QGuiActionGroupPrivate; + +class Q_GUI_EXPORT QGuiActionGroup : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QGuiActionGroup) + + Q_PROPERTY(QGuiActionGroup::ExclusionPolicy exclusionPolicy READ exclusionPolicy WRITE setExclusionPolicy) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible) + +public: + enum class ExclusionPolicy { + None, + Exclusive, + ExclusiveOptional + }; + Q_ENUM(ExclusionPolicy) + + explicit QGuiActionGroup(QObject *parent); + ~QGuiActionGroup(); + + QGuiAction *addAction(QGuiAction *a); + void removeAction(QGuiAction *a); + QList<QGuiAction*> guiActions() const; + QGuiAction *checkedGuiAction() const; + + bool isExclusive() const; + bool isEnabled() const; + bool isVisible() const; + ExclusionPolicy exclusionPolicy() const; + + +public Q_SLOTS: + void setEnabled(bool); + inline void setDisabled(bool b) { setEnabled(!b); } + void setVisible(bool); + void setExclusive(bool); + void setExclusionPolicy(ExclusionPolicy policy); + +private Q_SLOTS: + void _q_actionTriggered(); + void _q_actionHovered(); + void _q_actionChanged(); + +protected: + QGuiActionGroup(QGuiActionGroupPrivate &dd, QObject *parent); + +private: + Q_DISABLE_COPY(QGuiActionGroup) +}; + +QT_END_NAMESPACE + +#endif // QGUIACTIONGROUP_H diff --git a/src/gui/image/qimage_compat.cpp b/src/gui/kernel/qguiactiongroup_p.h index ba31a9ac9b..99a58262c9 100644 --- a/src/gui/image/qimage_compat.cpp +++ b/src/gui/kernel/qguiactiongroup_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -37,30 +37,55 @@ ** ****************************************************************************/ -#ifdef QIMAGE_H -# error "This file cannot be used with precompiled headers" +#ifndef QGUIACTIONGROUP_P_H +#define QGUIACTIONGROUP_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtGui/private/qtguiglobal_p.h> +#include <QtGui/qguiactiongroup.h> +#include <QtGui/qfont.h> +#if QT_CONFIG(shortcut) +# include <QtGui/private/qshortcutmap_p.h> #endif -#define QT_COMPILING_QIMAGE_COMPAT_CPP +#include "private/qobject_p.h" -#include "qimage.h" +QT_REQUIRE_CONFIG(action); QT_BEGIN_NAMESPACE -// These implementations must be the same as the inline versions in qimage.h - -QImage QImage::convertToFormat(Format f, Qt::ImageConversionFlags flags) const +class Q_GUI_EXPORT QGuiActionGroupPrivate : public QObjectPrivate { - return convertToFormat_helper(f, flags); -} + Q_DECLARE_PUBLIC(QGuiActionGroup) +public: + enum Signal { Triggered, Hovered }; -QImage QImage::mirrored(bool horizontally, bool vertically) const -{ - return mirrored_helper(horizontally, vertically); -} + QGuiActionGroupPrivate(); + ~QGuiActionGroupPrivate(); -QImage QImage::rgbSwapped() const -{ - return rgbSwapped_helper(); -} + virtual void emitSignal(Signal, QGuiAction *) {} + + QList<QGuiAction *> actions; + QPointer<QGuiAction> current; + uint enabled : 1; + uint visible : 1; + QGuiActionGroup::ExclusionPolicy exclusionPolicy = QGuiActionGroup::ExclusionPolicy::Exclusive; + +private: + void _q_actionTriggered(); //private slot + void _q_actionChanged(); //private slot + void _q_actionHovered(); //private slot +}; QT_END_NAMESPACE + +#endif // QACTIONGROUP_P_H diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index ef31e475ea..5869d024f0 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1184,14 +1184,18 @@ Q_LOGGING_CATEGORY(lcQpaPluginLoading, "qt.qpa.plugin"); static void init_platform(const QString &pluginNamesWithArguments, const QString &platformPluginPath, const QString &platformThemeName, int &argc, char **argv) { - QStringList plugins = pluginNamesWithArguments.split(QLatin1Char(';')); + QStringList plugins = pluginNamesWithArguments.split(QLatin1Char(';'), QString::SkipEmptyParts); QStringList platformArguments; QStringList availablePlugins = QPlatformIntegrationFactory::keys(platformPluginPath); for (const auto &pluginArgument : plugins) { // Split into platform name and arguments - QStringList arguments = pluginArgument.split(QLatin1Char(':')); + QStringList arguments = pluginArgument.split(QLatin1Char(':'), QString::SkipEmptyParts); + if (arguments.isEmpty()) + continue; const QString name = arguments.takeFirst().toLower(); QString argumentsKey = name; + if (name.isEmpty()) + continue; argumentsKey[0] = argumentsKey.at(0).toUpper(); arguments.append(QLibraryInfo::platformPluginArguments(argumentsKey)); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index ee493faa5d..9f3fa7212a 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -62,7 +62,10 @@ #include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface_p.h> -#include "private/qshortcutmap_p.h" +#if QT_CONFIG(shortcut) +# include "private/qshortcutmap_p.h" +#endif + #include <qicon.h> QT_BEGIN_NAMESPACE @@ -263,7 +266,7 @@ public: QIcon forcedWindowIcon; static QList<QObject *> generic_plugin_list; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) QShortcutMap shortcutMap; #endif diff --git a/src/gui/kernel/qguishortcut.cpp b/src/gui/kernel/qguishortcut.cpp new file mode 100644 index 0000000000..add1dce12e --- /dev/null +++ b/src/gui/kernel/qguishortcut.cpp @@ -0,0 +1,354 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qguishortcut.h" +#include "qguishortcut_p.h" + +#include <qevent.h> +#include <qguiapplication.h> +#include <qwindow.h> +#include <private/qguiapplication_p.h> +#include <qpa/qplatformmenu.h> + +QT_BEGIN_NAMESPACE + +#define QAPP_CHECK(functionName) \ + if (Q_UNLIKELY(!qApp)) { \ + qWarning("QGuiShortcut: Initialize QGuiApplication before calling '" functionName "'."); \ + return; \ + } + +/*! + \class QGuiShortcut + \brief The QGuiShortcut class is a base class for handling keyboard shortcuts. + + \ingroup events + \inmodule QtGui + \since 6.0 + + The QGuiShortcut class is a base class for classes providing a way of + connecting keyboard shortcuts to Qt's \l{signals and slots} mechanism, + so that objects can be informed when a shortcut is executed. The shortcut + can be set up to contain all the key presses necessary to + describe a keyboard shortcut, including the states of modifier + keys such as \uicontrol Shift, \uicontrol Ctrl, and \uicontrol Alt. + + \target mnemonic + + \sa QShortcutEvent, QKeySequence, QAction +*/ + +/*! + \fn void QGuiShortcut::activated() + + This signal is emitted when the user types the shortcut's key + sequence. + + \sa activatedAmbiguously() +*/ + +/*! + \fn void QGuiShortcut::activatedAmbiguously() + + When a key sequence is being typed at the keyboard, it is said to + be ambiguous as long as it matches the start of more than one + shortcut. + + When a shortcut's key sequence is completed, + activatedAmbiguously() is emitted if the key sequence is still + ambiguous (i.e., it is the start of one or more other shortcuts). + The activated() signal is not emitted in this case. + + \sa activated() +*/ + +static bool simpleContextMatcher(QObject *object, Qt::ShortcutContext context) +{ + auto guiShortcut = qobject_cast<QGuiShortcut *>(object); + if (QGuiApplication::applicationState() != Qt::ApplicationActive || guiShortcut == nullptr) + return false; + if (context == Qt::ApplicationShortcut) + return true; + auto focusWindow = QGuiApplication::focusWindow(); + if (!focusWindow) + return false; + auto window = qobject_cast<const QWindow *>(guiShortcut->parent()); + if (!window) + return false; + if (focusWindow == window && focusWindow->isTopLevel()) + return context == Qt::WindowShortcut || context == Qt::WidgetWithChildrenShortcut; + return focusWindow->isAncestorOf(window, QWindow::ExcludeTransients); +} + +QShortcutMap::ContextMatcher QGuiShortcutPrivate::contextMatcher() const +{ + return simpleContextMatcher; +} + +void QGuiShortcutPrivate::redoGrab(QShortcutMap &map) +{ + Q_Q(QGuiShortcut); + if (Q_UNLIKELY(!parent)) { + qWarning("QGuiShortcut: No window parent defined"); + return; + } + + if (sc_id) + map.removeShortcut(sc_id, q); + if (sc_sequence.isEmpty()) + return; + sc_id = map.addShortcut(q, sc_sequence, sc_context, contextMatcher()); + if (!sc_enabled) + map.setShortcutEnabled(false, sc_id, q); + if (!sc_autorepeat) + map.setShortcutAutoRepeat(false, sc_id, q); +} + +/*! + Constructs a QGuiShortcut object for the \a parent window. Since no + shortcut key sequence is specified, the shortcut will not emit any + signals. + + \sa setKey() +*/ +QGuiShortcut::QGuiShortcut(QWindow *parent) + : QGuiShortcut(*new QGuiShortcutPrivate, parent) +{ +} + +/*! + Constructs a QGuiShortcut object for the \a parent window. The shortcut + operates on its parent, listening for \l{QShortcutEvent}s that + match the \a key sequence. Depending on the ambiguity of the + event, the shortcut will call the \a member function, or the \a + ambiguousMember function, if the key press was in the shortcut's + \a context. +*/ +QGuiShortcut::QGuiShortcut(const QKeySequence &key, QWindow *parent, + const char *member, const char *ambiguousMember, + Qt::ShortcutContext context) + : QGuiShortcut(*new QGuiShortcutPrivate, key, parent, member, ambiguousMember, context) +{ +} + +/*! + \internal +*/ +QGuiShortcut::QGuiShortcut(QGuiShortcutPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ + Q_ASSERT(parent != nullptr); +} + +/*! + \internal +*/ +QGuiShortcut::QGuiShortcut(QGuiShortcutPrivate &dd, + const QKeySequence &key, QObject *parent, + const char *member, const char *ambiguousMember, + Qt::ShortcutContext context) + : QGuiShortcut(dd, parent) +{ + QAPP_CHECK("QGuiShortcut"); + + Q_D(QGuiShortcut); + d->sc_context = context; + d->sc_sequence = key; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); + if (member) + connect(this, SIGNAL(activated()), parent, member); + if (ambiguousMember) + connect(this, SIGNAL(activatedAmbiguously()), parent, ambiguousMember); +} + +/*! + Destroys the shortcut. +*/ +QGuiShortcut::~QGuiShortcut() +{ + Q_D(QGuiShortcut); + if (qApp) + QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(d->sc_id, this); +} + +/*! + \property QGuiShortcut::key + \brief the shortcut's key sequence + + This is a key sequence with an optional combination of Shift, Ctrl, + and Alt. The key sequence may be supplied in a number of ways: + + \snippet code/src_gui_kernel_qshortcut.cpp 1 + + By default, this property contains an empty key sequence. +*/ +void QGuiShortcut::setKey(const QKeySequence &key) +{ + Q_D(QGuiShortcut); + if (d->sc_sequence == key) + return; + QAPP_CHECK("setKey"); + d->sc_sequence = key; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); +} + +QKeySequence QGuiShortcut::key() const +{ + Q_D(const QGuiShortcut); + return d->sc_sequence; +} + +/*! + \property QGuiShortcut::enabled + \brief whether the shortcut is enabled + + An enabled shortcut emits the activated() or activatedAmbiguously() + signal when a QShortcutEvent occurs that matches the shortcut's + key() sequence. + + If the application is in \c WhatsThis mode the shortcut will not emit + the signals, but will show the "What's This?" text instead. + + By default, this property is \c true. + + \sa whatsThis +*/ +void QGuiShortcut::setEnabled(bool enable) +{ + Q_D(QGuiShortcut); + if (d->sc_enabled == enable) + return; + QAPP_CHECK("setEnabled"); + d->sc_enabled = enable; + QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enable, d->sc_id, this); +} + +bool QGuiShortcut::isEnabled() const +{ + Q_D(const QGuiShortcut); + return d->sc_enabled; +} + +/*! + \property QGuiShortcut::context + \brief the context in which the shortcut is valid + + A shortcut's context decides in which circumstances a shortcut is + allowed to be triggered. The normal context is Qt::WindowShortcut, + which allows the shortcut to trigger if the parent (the widget + containing the shortcut) is a subwidget of the active top-level + window. + + By default, this property is set to Qt::WindowShortcut. +*/ +void QGuiShortcut::setContext(Qt::ShortcutContext context) +{ + Q_D(QGuiShortcut); + if (d->sc_context == context) + return; + QAPP_CHECK("setContext"); + d->sc_context = context; + d->redoGrab(QGuiApplicationPrivate::instance()->shortcutMap); +} + +Qt::ShortcutContext QGuiShortcut::context() const +{ + Q_D(const QGuiShortcut); + return d->sc_context; +} + +/*! + \property QGuiShortcut::autoRepeat + \brief whether the shortcut can auto repeat + + If true, the shortcut will auto repeat when the keyboard shortcut + combination is held down, provided that keyboard auto repeat is + enabled on the system. + The default value is true. +*/ +void QGuiShortcut::setAutoRepeat(bool on) +{ + Q_D(QGuiShortcut); + if (d->sc_autorepeat == on) + return; + QAPP_CHECK("setAutoRepeat"); + d->sc_autorepeat = on; + QGuiApplicationPrivate::instance()->shortcutMap.setShortcutAutoRepeat(on, d->sc_id, this); +} + +bool QGuiShortcut::autoRepeat() const +{ + Q_D(const QGuiShortcut); + return d->sc_autorepeat; +} + +/*! + Returns the shortcut's ID. + + \sa QShortcutEvent::shortcutId() +*/ +int QGuiShortcut::id() const +{ + Q_D(const QGuiShortcut); + return d->sc_id; +} + +/*! + \internal +*/ +bool QGuiShortcut::event(QEvent *e) +{ + Q_D(QGuiShortcut); + if (d->sc_enabled && e->type() == QEvent::Shortcut) { + auto se = static_cast<QShortcutEvent *>(e); + if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence + && !d->handleWhatsThis()) { + if (se->isAmbiguous()) + emit activatedAmbiguously(); + else + emit activated(); + return true; + } + } + return QObject::event(e); +} + +QT_END_NAMESPACE + +#include "moc_qguishortcut.cpp" diff --git a/src/gui/kernel/qguishortcut.h b/src/gui/kernel/qguishortcut.h new file mode 100644 index 0000000000..fb64f10c84 --- /dev/null +++ b/src/gui/kernel/qguishortcut.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGUISHORTCUT_H +#define QGUISHORTCUT_H + +#include <QtGui/qtguiglobal.h> +#include <QtGui/qkeysequence.h> +#include <QtCore/qobject.h> + +QT_REQUIRE_CONFIG(shortcut); + +QT_BEGIN_NAMESPACE + +class QGuiShortcutPrivate; +class QWindow; + +class Q_GUI_EXPORT QGuiShortcut : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QGuiShortcut) + Q_PROPERTY(QKeySequence key READ key WRITE setKey) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) + Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat) + Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext) +public: + explicit QGuiShortcut(QWindow *parent); + explicit QGuiShortcut(const QKeySequence& key, QWindow *parent, + const char *member = nullptr, const char *ambiguousMember = nullptr, + Qt::ShortcutContext context = Qt::WindowShortcut); + ~QGuiShortcut(); + + void setKey(const QKeySequence& key); + QKeySequence key() const; + + void setEnabled(bool enable); + bool isEnabled() const; + + void setContext(Qt::ShortcutContext context); + Qt::ShortcutContext context() const; + + void setAutoRepeat(bool on); + bool autoRepeat() const; + + int id() const; + +Q_SIGNALS: + void activated(); + void activatedAmbiguously(); + +protected: + QGuiShortcut(QGuiShortcutPrivate &dd, QObject *parent); + QGuiShortcut(QGuiShortcutPrivate &dd, const QKeySequence& key, QObject *parent, + const char *member, const char *ambiguousMember, + Qt::ShortcutContext context); + + bool event(QEvent *e) override; +}; + +QT_END_NAMESPACE + +#endif // QGUISHORTCUT_H diff --git a/src/gui/image/qpictureformatplugin.h b/src/gui/kernel/qguishortcut_p.h index 3f59c04d79..420b02ef1a 100644 --- a/src/gui/image/qpictureformatplugin.h +++ b/src/gui/kernel/qguishortcut_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -37,40 +37,56 @@ ** ****************************************************************************/ -#ifndef QPICTUREFORMATPLUGIN_H -#define QPICTUREFORMATPLUGIN_H +#ifndef QGUISHORTCUT_P_H +#define QGUISHORTCUT_P_H -#include <QtGui/qtguiglobal.h> -#include <QtCore/qplugin.h> -#include <QtCore/qfactoryinterface.h> +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// -QT_BEGIN_NAMESPACE +#include <QtGui/private/qtguiglobal_p.h> +#include "qguishortcut.h" +#include <QtGui/qkeysequence.h> + +#include <QtCore/qstring.h> +#include <QtCore/private/qobject_p.h> +#include <private/qshortcutmap_p.h> -#if !defined(QT_NO_PICTURE) -class QPicture; -class QImage; -class QString; -class QStringList; -#define QPictureFormatInterface_iid "org.qt-project.Qt.QPictureFormatInterface" +QT_BEGIN_NAMESPACE -class Q_GUI_EXPORT QPictureFormatPlugin : public QObject +class QShortcutMap; + +/* + \internal + Private data accessed through d-pointer. +*/ +class Q_GUI_EXPORT QGuiShortcutPrivate : public QObjectPrivate { - Q_OBJECT + Q_DECLARE_PUBLIC(QGuiShortcut) public: - explicit QPictureFormatPlugin(QObject *parent = nullptr); - ~QPictureFormatPlugin(); + QGuiShortcutPrivate() = default; - virtual bool loadPicture(const QString &format, const QString &filename, QPicture *pic); - virtual bool savePicture(const QString &format, const QString &filename, const QPicture &pic); - virtual bool installIOHandler(const QString &format) = 0; + virtual QShortcutMap::ContextMatcher contextMatcher() const; + virtual bool handleWhatsThis() { return false; } + QKeySequence sc_sequence; + Qt::ShortcutContext sc_context = Qt::WindowShortcut; + bool sc_enabled = true; + bool sc_autorepeat = true; + int sc_id = 0; + void redoGrab(QShortcutMap &map); }; -#endif // QT_NO_PICTURE - QT_END_NAMESPACE -#endif // QPICTUREFORMATPLUGIN_H +#endif // QGUISHORTCUT_P_H diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index edca8d9423..2d6d12cc21 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -44,7 +44,9 @@ #include "qcursor.h" #include "qfont.h" #include "qimage.h" -#include "qkeysequence.h" +#if QT_CONFIG(shortcut) +# include "qkeysequence.h" +#endif #include "qtransform.h" #include "qmatrix.h" #include "qpalette.h" @@ -188,7 +190,7 @@ static bool convert(const QVariant::Private *d, int t, case QVariant::String: { QString *str = static_cast<QString *>(result); switch (d->type) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QVariant::KeySequence: *str = (*v_cast<QKeySequence>(d)).toString(QKeySequence::NativeText); return true; @@ -238,7 +240,7 @@ static bool convert(const QVariant::Private *d, int t, return true; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QVariant::Int: if (d->type == QVariant::KeySequence) { const QKeySequence &seq = *v_cast<QKeySequence>(d); @@ -277,7 +279,7 @@ static bool convert(const QVariant::Private *d, int t, return true; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QVariant::KeySequence: { QKeySequence *seq = static_cast<QKeySequence *>(result); switch (d->type) { diff --git a/src/gui/kernel/qkeymapper_p.h b/src/gui/kernel/qkeymapper_p.h index 8364557020..fd53747fdd 100644 --- a/src/gui/kernel/qkeymapper_p.h +++ b/src/gui/kernel/qkeymapper_p.h @@ -53,7 +53,6 @@ #include <QtGui/private/qtguiglobal_p.h> #include <qobject.h> #include <private/qobject_p.h> -#include <qkeysequence.h> #include <qlist.h> #include <qlocale.h> #include <qevent.h> diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index e1244e1006..d5bdf1f15b 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -42,8 +42,6 @@ #include <qpa/qplatformtheme.h> #include "private/qguiapplication_p.h" -#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC) - #include "qdebug.h" #include <QtCore/qhashfunctions.h> #ifndef QT_NO_DATASTREAM @@ -1679,9 +1677,6 @@ QDebug operator<<(QDebug dbg, const QKeySequence &p) } #endif -#endif // QT_NO_SHORTCUT - - /*! \typedef QKeySequence::DataPtr \internal diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h index 3dcbbe5941..68f256c37a 100644 --- a/src/gui/kernel/qkeysequence.h +++ b/src/gui/kernel/qkeysequence.h @@ -44,10 +44,9 @@ #include <QtCore/qstring.h> #include <QtCore/qobjectdefs.h> -QT_BEGIN_NAMESPACE - +QT_REQUIRE_CONFIG(shortcut); -#if !defined(QT_NO_SHORTCUT) || defined(Q_CLANG_QDOC) +QT_BEGIN_NAMESPACE class QKeySequence; @@ -227,17 +226,6 @@ Q_DECLARE_SHARED(QKeySequence) Q_GUI_EXPORT QDebug operator<<(QDebug, const QKeySequence &); #endif -#else - -class Q_GUI_EXPORT QKeySequence -{ -public: - QKeySequence() {} - QKeySequence(int) {} -}; - -#endif // QT_NO_SHORTCUT - QT_END_NAMESPACE #endif // QKEYSEQUENCE_H diff --git a/src/gui/kernel/qkeysequence_p.h b/src/gui/kernel/qkeysequence_p.h index fbcab5d34e..8c59505561 100644 --- a/src/gui/kernel/qkeysequence_p.h +++ b/src/gui/kernel/qkeysequence_p.h @@ -56,9 +56,10 @@ #include <algorithm> +QT_REQUIRE_CONFIG(shortcut); + QT_BEGIN_NAMESPACE -#ifndef QT_NO_SHORTCUT struct QKeyBinding { QKeySequence::StandardKey standardKey; @@ -87,7 +88,6 @@ public: Q_GUI_EXPORT static QString keyName(int key, QKeySequence::SequenceFormat format); static int decodeString(QString accel, QKeySequence::SequenceFormat format); }; -#endif // QT_NO_SHORTCUT QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h index 28c29a704c..8e470aefd3 100644 --- a/src/gui/kernel/qplatformmenu.h +++ b/src/gui/kernel/qplatformmenu.h @@ -52,7 +52,9 @@ #include <QtGui/qtguiglobal.h> #include <QtCore/qpointer.h> #include <QtGui/QFont> -#include <QtGui/QKeySequence> +#if QT_CONFIG(shortcut) +# include <QtGui/QKeySequence> +#endif #include <QtGui/QIcon> QT_BEGIN_NAMESPACE @@ -85,7 +87,7 @@ public: virtual void setRole(MenuRole role) = 0; virtual void setCheckable(bool checkable) = 0; virtual void setChecked(bool isChecked) = 0; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) virtual void setShortcut(const QKeySequence& shortcut) = 0; #endif virtual void setEnabled(bool enabled) = 0; diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index f906f808d8..ff6f32de10 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -167,7 +167,7 @@ QT_BEGIN_NAMESPACE */ -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) // Table of key bindings. It must be sorted on key sequence: // The integer value of VK_KEY | Modifier Keys (e.g., VK_META, and etc.) // A priority of 1 indicates that this is the primary key binding when multiple are defined. @@ -623,7 +623,7 @@ static inline int maybeSwapShortcut(int shortcut) } #endif -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) // mixed-mode predicate: all of these overloads are actually needed (but not all for every compiler) struct ByStandardKey { typedef bool result_type; @@ -688,6 +688,7 @@ QString QPlatformTheme::standardButtonText(int button) const return QPlatformTheme::defaultStandardButtonText(button); } +#if QT_CONFIG(shortcut) /*! Returns the mnemonic that should be used for a standard \a button. @@ -700,6 +701,7 @@ QKeySequence QPlatformTheme::standardButtonShortcut(int button) const Q_UNUSED(button) return QKeySequence(); } +#endif // QT_CONFIG(shortcut) QString QPlatformTheme::defaultStandardButtonText(int button) { @@ -784,7 +786,7 @@ unsigned QPlatformThemePrivate::currentKeyPlatforms() { const uint keyboardScheme = QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt(); unsigned result = 1u << keyboardScheme; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) if (keyboardScheme == QPlatformTheme::KdeKeyboardScheme || keyboardScheme == QPlatformTheme::GnomeKeyboardScheme || keyboardScheme == QPlatformTheme::CdeKeyboardScheme) diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 3185fc4541..6ed612b785 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -51,7 +51,9 @@ #include <QtGui/qtguiglobal.h> #include <QtCore/QScopedPointer> -#include <QtGui/QKeySequence> +#if QT_CONFIG(shortcut) +# include <QtGui/QKeySequence> +#endif QT_BEGIN_NAMESPACE @@ -312,12 +314,14 @@ public: QPlatformTheme::IconOptions iconOptions = { }) const; virtual QIconEngine *createIconEngine(const QString &iconName) const; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) virtual QList<QKeySequence> keyBindings(QKeySequence::StandardKey key) const; #endif virtual QString standardButtonText(int button) const; +#if QT_CONFIG(shortcut) virtual QKeySequence standardButtonShortcut(int button) const; +#endif static QVariant defaultThemeHint(ThemeHint hint); static QString defaultStandardButtonText(int button); diff --git a/src/gui/kernel/qplatformtheme_p.h b/src/gui/kernel/qplatformtheme_p.h index 73deb890bb..2c16fec141 100644 --- a/src/gui/kernel/qplatformtheme_p.h +++ b/src/gui/kernel/qplatformtheme_p.h @@ -52,7 +52,9 @@ // #include <QtGui/private/qtguiglobal_p.h> -#include "private/qkeysequence_p.h" +#if QT_CONFIG(shortcut) +# include "private/qkeysequence_p.h" +#endif QT_BEGIN_NAMESPACE @@ -67,7 +69,7 @@ public: void initializeSystemPalette(); -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) static const QKeyBinding keyBindings[]; static const uint numberOfKeyBindings; #endif diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index 9ed450b031..1d244d97e8 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -49,8 +49,6 @@ #include <algorithm> -#ifndef QT_NO_SHORTCUT - QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcShortcutMap, "qt.gui.shortcutmap") @@ -689,5 +687,3 @@ void QShortcutMap::dumpMap() const #endif QT_END_NAMESPACE - -#endif // QT_NO_SHORTCUT diff --git a/src/gui/kernel/qshortcutmap_p.h b/src/gui/kernel/qshortcutmap_p.h index 8fc68229fb..aa3dd969f0 100644 --- a/src/gui/kernel/qshortcutmap_p.h +++ b/src/gui/kernel/qshortcutmap_p.h @@ -56,9 +56,9 @@ #include "QtCore/qvector.h" #include "QtCore/qscopedpointer.h" -QT_BEGIN_NAMESPACE +QT_REQUIRE_CONFIG(shortcut); -#ifndef QT_NO_SHORTCUT +QT_BEGIN_NAMESPACE // To enable dump output uncomment below //#define Dump_QShortcutMap @@ -106,8 +106,6 @@ private: QScopedPointer<QShortcutMapPrivate> d_ptr; }; -#endif // QT_NO_SHORTCUT - QT_END_NAMESPACE #endif // QSHORTCUTMAP_P_H diff --git a/src/gui/kernel/qwindowdefs.h b/src/gui/kernel/qwindowdefs.h index b4f3ed4712..cb0842da8c 100644 --- a/src/gui/kernel/qwindowdefs.h +++ b/src/gui/kernel/qwindowdefs.h @@ -43,6 +43,7 @@ #include <QtGui/qtguiglobal.h> #include <QtCore/qobjectdefs.h> #include <QtCore/qnamespace.h> +#include <QtCore/qcontainerfwd.h> QT_BEGIN_NAMESPACE @@ -80,7 +81,6 @@ class QString; class QByteArray; class QApplication; -template<typename T> class QList; typedef QList<QWidget *> QWidgetList; typedef QList<QWindow *> QWindowList; diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index ba04f8701d..286dfaa8cc 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -440,7 +440,7 @@ void QWindowSystemInterface::handleFrameStrutMouseEvent(QWindow *window, ulong t bool QWindowSystemInterface::handleShortcutEvent(QWindow *window, ulong timestamp, int keyCode, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text, bool autorepeat, ushort count) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) if (!window) window = QGuiApplication::focusWindow(); @@ -1245,7 +1245,7 @@ Q_GUI_EXPORT void qt_handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt:: Q_GUI_EXPORT bool qt_sendShortcutOverrideEvent(QObject *o, ulong timestamp, int k, Qt::KeyboardModifiers mods, const QString &text = QString(), bool autorep = false, ushort count = 1) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) // FIXME: This method should not allow targeting a specific object, but should // instead forward the event to a window, which then takes care of normal event diff --git a/src/gui/opengl/qopengltexture.cpp b/src/gui/opengl/qopengltexture.cpp index 61a6202017..ed58766dde 100644 --- a/src/gui/opengl/qopengltexture.cpp +++ b/src/gui/opengl/qopengltexture.cpp @@ -4612,7 +4612,7 @@ QOpenGLTexture::WrapMode QOpenGLTexture::wrapMode(QOpenGLTexture::CoordinateDire \note This function has no effect on Mac and Qt built for OpenGL ES 2. \sa borderColor() */ -void QOpenGLTexture::setBorderColor(QColor color) +void QOpenGLTexture::setBorderColor(const QColor &color) { setBorderColor(static_cast<float>(color.redF()), static_cast<float>(color.greenF()), static_cast<float>(color.blueF()), static_cast<float>(color.alphaF())); diff --git a/src/gui/opengl/qopengltexture.h b/src/gui/opengl/qopengltexture.h index 7d984babc8..539b6aa7b2 100644 --- a/src/gui/opengl/qopengltexture.h +++ b/src/gui/opengl/qopengltexture.h @@ -621,7 +621,7 @@ public: void setWrapMode(CoordinateDirection direction, WrapMode mode); WrapMode wrapMode(CoordinateDirection direction) const; - void setBorderColor(QColor color); + void setBorderColor(const QColor &color); void setBorderColor(float r, float g, float b, float a); void setBorderColor(int r, int g, int b, int a); void setBorderColor(uint r, uint g, uint b, uint a); diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 8780cce223..c567b25468 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -855,18 +855,6 @@ QColor::QColor(Spec spec) noexcept */ /*! - Returns the name of the color in the format "#RRGGBB"; i.e. a "#" - character followed by three two-digit hexadecimal numbers. - - \sa setNamedColor() -*/ - -QString QColor::name() const -{ - return name(HexRgb); -} - -/*! \since 5.2 Returns the name of the color in the specified \a format. @@ -1086,6 +1074,7 @@ void QColor::setHsvF(qreal h, qreal s, qreal v, qreal a) || (v < qreal(0.0) || v > qreal(1.0)) || (a < qreal(0.0) || a > qreal(1.0))) { qWarning("QColor::setHsvF: HSV parameters out of range"); + invalidate(); return; } @@ -1198,7 +1187,8 @@ void QColor::setHslF(qreal h, qreal s, qreal l, qreal a) || (s < qreal(0.0) || s > qreal(1.0)) || (l < qreal(0.0) || l > qreal(1.0)) || (a < qreal(0.0) || a > qreal(1.0))) { - qWarning("QColor::setHsvF: HSV parameters out of range"); + qWarning("QColor::setHslF: HSL parameters out of range"); + invalidate(); return; } @@ -1224,7 +1214,7 @@ void QColor::setHslF(qreal h, qreal s, qreal l, qreal a) void QColor::setHsl(int h, int s, int l, int a) { if (h < -1 || (uint)s > 255 || (uint)l > 255 || (uint)a > 255) { - qWarning("QColor::setHsv: HSV parameters out of range"); + qWarning("QColor::setHsl: HSL parameters out of range"); invalidate(); return; } @@ -2626,16 +2616,6 @@ QColor QColor::fromHslF(qreal h, qreal s, qreal l, qreal a) } /*! - \obsolete - - Use the \c const overload instead. -*/ -void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a) -{ - const_cast<const QColor *>(this)->getCmyk(c, m, y, k, a); -} - -/*! Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color's CMYK value. @@ -2665,16 +2645,6 @@ void QColor::getCmyk(int *c, int *m, int *y, int *k, int *a) const } /*! - \obsolete - - Use the \c const overload instead. -*/ -void QColor::getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a) -{ - const_cast<const QColor *>(this)->getCmykF(c, m, y, k, a); -} - -/*! Sets the contents pointed to by \a c, \a m, \a y, \a k, and \a a, to the cyan, magenta, yellow, black, and alpha-channel (transparency) components of the color's CMYK value. @@ -2719,6 +2689,7 @@ void QColor::setCmyk(int c, int m, int y, int k, int a) || k < 0 || k > 255 || a < 0 || a > 255) { qWarning("QColor::setCmyk: CMYK parameters out of range"); + invalidate(); return; } @@ -2748,6 +2719,7 @@ void QColor::setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a) || k < qreal(0.0) || k > qreal(1.0) || a < qreal(0.0) || a > qreal(1.0)) { qWarning("QColor::setCmykF: CMYK parameters out of range"); + invalidate(); return; } @@ -2920,18 +2892,6 @@ QColor QColor::dark(int factor) const noexcept } #endif -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) -/*! - Assigns a copy of \a color to this color, and returns a reference to it. -*/ -QColor &QColor::operator=(const QColor &color) noexcept -{ - cspec = color.cspec; - ct.argb = color.ct.argb; - return *this; -} -#endif - /*! \overload Assigns a copy of \a color and returns a reference to this color. */ diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h index f0d7dd23ad..423a0ac50f 100644 --- a/src/gui/painting/qcolor.h +++ b/src/gui/painting/qcolor.h @@ -46,6 +46,8 @@ #include <QtCore/qstringlist.h> #include <QtGui/qrgba64.h> +#include <limits.h> + QT_BEGIN_NAMESPACE @@ -87,24 +89,11 @@ public: inline QColor(QLatin1String name); QColor(Spec spec) noexcept; -#if QT_VERSION < QT_VERSION_CHECK(6,0,0) - // ### Qt 6: remove all of these, the trivial ones are fine. - Q_DECL_CONSTEXPR QColor(const QColor &color) noexcept - : cspec(color.cspec), ct(color.ct) - {} - Q_DECL_CONSTEXPR QColor(QColor &&other) noexcept : cspec(other.cspec), ct(other.ct) {} - QColor &operator=(QColor &&other) noexcept - { cspec = other.cspec; ct = other.ct; return *this; } - QColor &operator=(const QColor &) noexcept; -#endif // Qt < 6 - QColor &operator=(Qt::GlobalColor color) noexcept; bool isValid() const noexcept; - // ### Qt 6: merge overloads - QString name() const; - QString name(NameFormat format) const; + QString name(NameFormat format = HexRgb) const; #if QT_STRINGVIEW_LEVEL < 2 void setNamedColor(const QString& name); @@ -180,11 +169,9 @@ public: qreal yellowF() const noexcept; qreal blackF() const noexcept; - void getCmyk(int *c, int *m, int *y, int *k, int *a = nullptr); // ### Qt 6: remove void getCmyk(int *c, int *m, int *y, int *k, int *a = nullptr) const; void setCmyk(int c, int m, int y, int k, int a = 255); - void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a = nullptr); // ### Qt 6: remove void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a = nullptr) const; void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0); diff --git a/src/gui/painting/qdrawhelper_ssse3.cpp b/src/gui/painting/qdrawhelper_ssse3.cpp index 14d7047bb6..a175b591dd 100644 --- a/src/gui/painting/qdrawhelper_ssse3.cpp +++ b/src/gui/painting/qdrawhelper_ssse3.cpp @@ -197,7 +197,7 @@ void qt_memfill24_ssse3(quint24 *dest, quint24 color, qsizetype count) quint24 *end = dest + count; constexpr uchar x = 2, y = 1, z = 0; - Q_DECL_ALIGN(__m128i) static const uchar + alignas(__m128i) static const uchar shuffleMask[16 + 1] = { x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y }; __m128i mval1 = _mm_shuffle_epi8(m, _mm_load_si128(reinterpret_cast<const __m128i *>(shuffleMask))); diff --git a/src/gui/text/qfontdatabase.h b/src/gui/text/qfontdatabase.h index 80b092f177..63e6b48e4f 100644 --- a/src/gui/text/qfontdatabase.h +++ b/src/gui/text/qfontdatabase.h @@ -49,7 +49,6 @@ QT_BEGIN_NAMESPACE class QStringList; -template <class T> class QList; struct QFontDef; class QFontEngine; diff --git a/src/gui/text/qfontengine_qpf2.cpp b/src/gui/text/qfontengine_qpf2.cpp index 409176d41b..36d1cd5b9b 100644 --- a/src/gui/text/qfontengine_qpf2.cpp +++ b/src/gui/text/qfontengine_qpf2.cpp @@ -168,7 +168,7 @@ const QFontEngineQPF2::Glyph *QFontEngineQPF2::findGlyph(glyph_t g) const bool QFontEngineQPF2::verifyHeader(const uchar *data, int size) { - VERIFY(quintptr(data) % Q_ALIGNOF(Header) == 0); + VERIFY(quintptr(data) % alignof(Header) == 0); VERIFY(size >= int(sizeof(Header))); const Header *header = reinterpret_cast<const Header *>(data); if (header->magic[0] != 'Q' diff --git a/src/gui/text/qtextoption.h b/src/gui/text/qtextoption.h index 8b57278633..a90d73dc43 100644 --- a/src/gui/text/qtextoption.h +++ b/src/gui/text/qtextoption.h @@ -48,8 +48,6 @@ QT_BEGIN_NAMESPACE - -template <typename T> class QList; struct QTextOptionPrivate; class Q_GUI_EXPORT QTextOption diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 024f0f084e..c33eb74995 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -960,7 +960,7 @@ void QGridLayoutEngine::insertItem(QGridLayoutItem *item, int index) { maybeExpandGrid(item->lastRow(), item->lastColumn()); - if (index == -1) + if (index < 0 || index >= q_items.size()) q_items.append(item); else q_items.insert(index, item); |