diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,7 +294,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpColorCells.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpColorPalette.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDefaultColorCollection.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDocumentSaveOptionsWidget.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDocumentSaveDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpDualColorButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpPrintDialogPage.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpTransparentColorCell.cpp @@ -332,11 +332,11 @@ add_executable(kolourpaint ${kolourpaint_SRCS}) target_link_libraries(kolourpaint - KF5::KDELibs4Support KF5::XmlGui KF5::IconThemes KF5::TextWidgets Qt5::PrintSupport + Qt5::Widgets ${KSANE_LIBRARIES} kolourpaint_lgpl ) diff --git a/document/kpDocument.cpp b/document/kpDocument.cpp --- a/document/kpDocument.cpp +++ b/document/kpDocument.cpp @@ -48,7 +48,8 @@ #include "kpLogCategories.h" -#include // kdelibs4support +#include +#include #include #include @@ -156,9 +157,16 @@ return true; } - return (!m_url.isEmpty () && - KIO::NetAccess::exists (m_url, KIO::NetAccess::SourceSide/*open*/, - d->environ->dialogParent ())); + if (m_url.isEmpty()) { + return false; + } + + // 0 == only check if the file exists, don't bother with file metadata + KIO::StatJob *statJob = KIO::stat(m_url, KIO::StatJob::SourceSide, 0); + KJobWidgets::setWindow(statJob, d->environ->dialogParent()); + const bool exists = statJob->exec(); + + return exists; } //--------------------------------------------------------------------- diff --git a/document/kpDocumentSaveOptions.h b/document/kpDocumentSaveOptions.h --- a/document/kpDocumentSaveOptions.h +++ b/document/kpDocumentSaveOptions.h @@ -32,6 +32,7 @@ class QImage; class QString; +class QStringList; class KConfigGroup; @@ -52,7 +53,6 @@ void printDebug (const QString &prefix) const; - QString mimeType () const; void setMimeType (const QString &mimeType); @@ -83,6 +83,8 @@ bool qualityIsInvalid () const; + static QStringList availableMimeTypes(); + // (All assume that 's group has been set) // (None of them call KConfigBase::reparseConfig() nor KConfigBase::sync()) diff --git a/document/kpDocumentSaveOptions.cpp b/document/kpDocumentSaveOptions.cpp --- a/document/kpDocumentSaveOptions.cpp +++ b/document/kpDocumentSaveOptions.cpp @@ -40,6 +40,7 @@ #include #include #include +#include //--------------------------------------------------------------------- @@ -271,6 +272,15 @@ return qualityIsInvalid (quality ()); } +QStringList kpDocumentSaveOptions::availableMimeTypes() +{ + QStringList mimeTypes; + for (const auto &type : QImageWriter::supportedMimeTypes()) { + mimeTypes << QString::fromLatin1(type); + } + return mimeTypes; +} + // public static QString kpDocumentSaveOptions::defaultMimeType (const KConfigGroup &config) diff --git a/document/kpDocument_Open.cpp b/document/kpDocument_Open.cpp --- a/document/kpDocument_Open.cpp +++ b/document/kpDocument_Open.cpp @@ -50,7 +50,10 @@ #include #include "kpLogCategories.h" -#include // kdelibs4support +#include +#include +#include +#include #include #include @@ -93,8 +96,19 @@ *metaInfo = kpDocumentMetaInfo (); } - QString tempFile; - if (url.isEmpty () || !KIO::NetAccess::download (url, tempFile, parent)) + if (!url.isValid() || (url.isLocalFile() && !QFile::exists(url.toLocalFile()))) { + if (!suppressDoesntExistDialog) { + KMessageBox::sorry (parent, + i18n ("\"%1\" is not valid valid file path.", + kpUrlFormatter::PrettyFilename (url))); + } + return {}; + } + + KIO::StoredTransferJob *downloadJob = KIO::storedGet(url); + KJobWidgets::setWindow(downloadJob, parent); + + if (!downloadJob->exec()) { if (!suppressDoesntExistDialog) { @@ -110,8 +124,11 @@ return {}; } + QBuffer downloadBuffer; + downloadBuffer.setData(downloadJob->data()); + QMimeDatabase db; - QMimeType mimeType = db.mimeTypeForFile(tempFile); + QMimeType mimeType = db.mimeTypeForData(downloadBuffer.data()); if (saveOptions) { saveOptions->setMimeType(mimeType.name()); @@ -123,20 +140,27 @@ qCDebug(kpLogDocument) << "\tsrc=" << url.path (); #endif - QImageReader reader(tempFile); + downloadBuffer.open(QIODevice::ReadOnly); + + QImageReader reader(&downloadBuffer); reader.setAutoTransform(true); reader.setDecideFormatFromContent(true); QImage image = reader.read(); - KIO::NetAccess::removeTempFile(tempFile); - if (image.isNull ()) { - KMessageBox::sorry (parent, - i18n ("Could not open \"%1\" - unsupported image format.\n" - "The file may be corrupt.", - kpUrlFormatter::PrettyFilename (url))); + if (reader.error() == QImageReader::UnsupportedFormatError) { + KMessageBox::sorry (parent, + i18n ("Could not open \"%1\" - unsupported image format.\n" + "The file may be corrupt.", + kpUrlFormatter::PrettyFilename (url))); + } else { + KMessageBox::sorry (parent, + i18n ("Could not open \"%1\".\n" + "The file may be corrupt.", + kpUrlFormatter::PrettyFilename (url))); + } return {}; } @@ -222,9 +246,17 @@ if (newDocSameNameIfNotExist) { - if (!url.isEmpty () && - // not just a permission error? - !KIO::NetAccess::exists (url, KIO::NetAccess::SourceSide/*open*/, d->environ->dialogParent ())) + if (url.isEmpty()) { + openNew (QUrl ()); + return true; + } + + // 0 == only check if the file exists, don't bother with file metadata + KIO::StatJob *statJob = KIO::stat(url, KIO::StatJob::SourceSide, 0); + KJobWidgets::setWindow(statJob, d->environ->dialogParent()); + const bool exists = statJob->exec(); + + if (exists) { openNew (url); } diff --git a/document/kpDocument_Save.cpp b/document/kpDocument_Save.cpp --- a/document/kpDocument_Save.cpp +++ b/document/kpDocument_Save.cpp @@ -46,12 +46,16 @@ #include #include #include +#include #include "kpLogCategories.h" -#include // kdelibs4support -#include // kdelibs4support +#include +#include +#include #include #include +#include +#include #include "imagelib/kpColor.h" #include "widgets/toolbars/kpColorToolBar.h" @@ -175,16 +179,40 @@ *userCancelled = false; } - QStringList types = KImageIO::typeForMime (saveOptions.mimeType ()); + if (saveOptions.mimeType().isEmpty()) { + return false; + } + + QList types; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) + types = QImageWriter::imageFormatsForMimeType(saveOptions.mimeType().toLocal8Bit()); +#else + QStringList typesStrings; + const KService::List services = KServiceTypeTrader::self()->query("QImageIOPlugins"); + for (const KService::Ptr &service : services) { + if (saveOptions.mimeType() != service->property("X-KDE-MimeType").toString()) { + continue; + } + typesStrings = service->property("X-KDE-ImageFormat").toStringList(); + if (!typesStrings.isEmpty()) { + break; + } + } + for (const QString &type : typesStrings) { + types.append(type.toLatin1()); + } +#endif + #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "\ttypes=" << types; #endif + if (types.isEmpty ()) { return false; } // It's safe to arbitrarily choose the 0th type as any type in the list // should invoke the same KImageIO image loader. - const QString type = types [0]; + const QByteArray type = types [0]; #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "\tmimeType=" << saveOptions.mimeType () @@ -271,7 +299,7 @@ #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "\tsaving"; #endif - if (!imageToSave.save (device, type.toLatin1 (), quality)) + if (!imageToSave.save (device, type, quality)) { #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "\tQImage::save() returned false"; @@ -318,6 +346,8 @@ // TODO: Use KIO::NetAccess:mostLocalURL() for accessing home:/ (and other // such local URLs) for efficiency and because only local writes // are atomic. + // -> But we use QSaveFile for atomicness, and that doesn't seem to be able + // to warn about file already existing, so we can't get 100% atomic #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "kpDocument::savePixmapToFile (" << url @@ -328,23 +358,28 @@ metaInfo.printDebug (QLatin1String ("\tmetaInfo")); #endif - if (overwritePrompt && - KIO::NetAccess::exists (url, KIO::NetAccess::DestinationSide/*write*/, parent)) - { - int result = KMessageBox::warningContinueCancel (parent, - i18n ("A document called \"%1\" already exists.\n" - "Do you want to overwrite it?", - kpUrlFormatter::PrettyFilename (url)), - QString(), - KStandardGuiItem::overwrite ()); + if (overwritePrompt) { + // 0 == only check if the file exists, don't bother with file metadata + KIO::StatJob *statJob = KIO::stat(url, KIO::StatJob::SourceSide, 0); + KJobWidgets::setWindow(statJob, parent); + const bool exists = statJob->exec(); - if (result != KMessageBox::Continue) - { - #if DEBUG_KP_DOCUMENT - qCDebug(kpLogDocument) << "\tuser doesn't want to overwrite"; - #endif + if (exists) { + int result = KMessageBox::warningContinueCancel (parent, + i18n ("A document called \"%1\" already exists.\n" + "Do you want to overwrite it?", + kpUrlFormatter::PrettyFilename (url)), + QString(), + KStandardGuiItem::overwrite ()); - return false; + if (result != KMessageBox::Continue) + { +#if DEBUG_KP_DOCUMENT + qCDebug(kpLogDocument) << "\tuser doesn't want to overwrite"; +#endif + + return false; + } } } @@ -463,7 +498,9 @@ // TODO: No one seems to know how to do this atomically // [http://lists.kde.org/?l=kde-core-devel&m=117845162728484&w=2]. // At least, fish:// (ssh) is definitely not atomic. - if (!KIO::NetAccess::upload (tempFileName, url, parent)) + KIO::FileCopyJob *uploadJob = KIO::file_copy(QUrl::fromLocalFile(tempFileName), url, -1, KIO::Overwrite); + KJobWidgets::setWindow(uploadJob, parent); + if (!uploadJob->exec()) { #if DEBUG_KP_DOCUMENT qCDebug(kpLogDocument) << "\treturning false because could not upload"; diff --git a/imagelib/effects/blitz.cpp b/imagelib/effects/blitz.cpp --- a/imagelib/effects/blitz.cpp +++ b/imagelib/effects/blitz.cpp @@ -65,8 +65,15 @@ #include "blitz.h" #include +#include #include +#if defined(Q_CC_CLANG) +#define IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wcast-align") body QT_WARNING_POP +#else +#define IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP +#endif + #define M_SQ2PI 2.50662827463100024161235523934010416269302368164062 #define M_EPSILON 1.0e-6 @@ -149,7 +156,7 @@ // form histogram memset(histogram, 0, 256*sizeof(HistogramListItem)); - dest = (QRgb *)img.bits(); + IGNORE_ALIGN(dest = (QRgb *)img.bits();) if(img.format() == QImage::Format_ARGB32_Premultiplied){ for(i=0; i < count; ++i, ++dest){ @@ -198,7 +205,8 @@ } // stretch the histogram and write - dest = (QRgb *)img.bits(); + IGNORE_ALIGN(dest = (QRgb *)img.bits();) + if(img.format() == QImage::Format_ARGB32_Premultiplied){ for(i=0; i < count; ++i, ++dest){ pixel = convertFromPremult(*dest); @@ -280,7 +288,7 @@ mh = height - my; } - p1 = (QRgb*)buffer.scanLine(y); + IGNORE_ALIGN(p1 = (QRgb*)buffer.scanLine(y);) memset(as, 0, static_cast(width) * sizeof(int)); memset(rs, 0, static_cast(width) * sizeof(int)); @@ -292,7 +300,7 @@ case QImage::Format_ARGB32_Premultiplied: { QRgb pixel; for (auto i = 0; i < mh; i++) { - p2 = (QRgb *)img.scanLine(i + my); + IGNORE_ALIGN(p2 = (QRgb *)img.scanLine(i + my);) for (auto j = 0; j < width; ++j) { p2++; pixel = convertFromPremult(*p2); @@ -324,7 +332,7 @@ default: { for (auto i = 0; i < mh; ++i) { - p2 = (QRgb *)img.scanLine(i + my); + IGNORE_ALIGN(p2 = (QRgb *)img.scanLine(i + my);) for (auto j = 0; j < width; j++) { p2++; as[j] += qAlpha(*p2); @@ -473,13 +481,13 @@ float r, g, b; for(y=0; y < h; ++y){ - src = (QRgb *)img.scanLine(y); - dest = (QRgb *)buffer.scanLine(y); + IGNORE_ALIGN(src = (QRgb *)img.scanLine(y);) + IGNORE_ALIGN(dest = (QRgb *)buffer.scanLine(y);) // Read in scanlines to pixel neighborhood. If the scanline is outside // the image use the top or bottom edge. for(x=y-edge, i=0; x <= y+edge; ++i, ++x){ - scanblock[i] = (QRgb *) - img.scanLine((x < 0) ? 0 : (x > h-1) ? h-1 : x); + IGNORE_ALIGN(scanblock[i] = (QRgb *) + img.scanLine((x < 0) ? 0 : (x > h-1) ? h-1 : x);) } // Now we are about to start processing scanlines. First handle the // part where the pixel neighborhood extends off the left edge. @@ -490,11 +498,11 @@ s = scanblock[matrix_y]; matrix_x = -edge; while(x+matrix_x < 0){ - CONVOLVE_ACC(*m, *s); + CONVOLVE_ACC(*m, *s) ++matrix_x; ++m; } while(matrix_x <= edge){ - CONVOLVE_ACC(*m, *s); + CONVOLVE_ACC(*m, *s) ++matrix_x; ++m; ++s; } } @@ -512,7 +520,7 @@ for(matrix_y = 0; matrix_y < matrix_size; ++matrix_y){ s = scanblock[matrix_y] + (x-edge); for(matrix_x = -edge; matrix_x <= edge; ++matrix_x, ++m, ++s){ - CONVOLVE_ACC(*m, *s); + CONVOLVE_ACC(*m, *s) } } r = r < 0.0f ? 0.0f : r > 255.0f ? 255.0f : r + 0.5f; @@ -531,14 +539,14 @@ s += x-edge; matrix_x = -edge; while(x+matrix_x < w){ - CONVOLVE_ACC(*m, *s); + CONVOLVE_ACC(*m, *s) ++matrix_x; ++m; ++s; } --s; while(matrix_x <= edge){ - CONVOLVE_ACC(*m, *s); + CONVOLVE_ACC(*m, *s) ++matrix_x; ++m; } @@ -650,7 +658,7 @@ } else{ - data = (unsigned int *)img.scanLine(0); + IGNORE_ALIGN(data = (unsigned int *)img.scanLine(0);) end = data + (img.width()*img.height()); } diff --git a/layers/selections/text/kpPreeditText.cpp b/layers/selections/text/kpPreeditText.cpp --- a/layers/selections/text/kpPreeditText.cpp +++ b/layers/selections/text/kpPreeditText.cpp @@ -73,7 +73,7 @@ break; } } - qSort (m_textFormatList.begin (), m_textFormatList.end (), attributeLessThan); + std::sort (m_textFormatList.begin (), m_textFormatList.end (), attributeLessThan); } //--------------------------------------------------------------------- diff --git a/layers/selections/text/kpTextSelection.cpp b/layers/selections/text/kpTextSelection.cpp --- a/layers/selections/text/kpTextSelection.cpp +++ b/layers/selections/text/kpTextSelection.cpp @@ -188,9 +188,13 @@ // public static int kpTextSelection::PreferredMinimumWidthForTextStyle (const kpTextStyle &textStyle) { - const int about15CharsWidth = - textStyle.fontMetrics ().width ( - QStringLiteral ("1234567890abcde")); + const int about15CharsWidth =textStyle.fontMetrics (). +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (QStringLiteral ("1234567890abcde")); const int preferredMinWidth = qMax (150, diff --git a/layers/selections/text/kpTextSelection_Cursor.cpp b/layers/selections/text/kpTextSelection_Cursor.cpp --- a/layers/selections/text/kpTextSelection_Cursor.cpp +++ b/layers/selections/text/kpTextSelection_Cursor.cpp @@ -74,13 +74,26 @@ const QFontMetrics fontMetrics (d->textStyle.fontMetrics ()); // (should be 0 but call just in case) - int charLocalLeft = fontMetrics.width (d->textLines [row], 0); + int charLocalLeft =fontMetrics. +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (d->textLines [row], 0); // OPT: binary search or guess location then move for (int col = 0; col < static_cast (d->textLines [row].length ()); col++) { // OPT: fontMetrics::charWidth() might be faster - const int nextCharLocalLeft = fontMetrics.width (d->textLines [row], col + 1); + const int nextCharLocalLeft = fontMetrics. +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + fontMetrics.width +#endif + (d->textLines [row], col + 1); + if (localX <= (charLocalLeft + nextCharLocalLeft) / 2) { return col; } @@ -119,7 +132,15 @@ { line.insert (preeditText.position ().x (), preeditText.preeditString ()); } - const int x = fontMetrics.width (line.left (col)); + + const int x =fontMetrics. +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (line.left (col)); + const int y = row * fontMetrics.height () + (row >= 1 ? row * fontMetrics.leading () : 0); diff --git a/layers/selections/text/kpTextSelection_Paint.cpp b/layers/selections/text/kpTextSelection_Paint.cpp --- a/layers/selections/text/kpTextSelection_Paint.cpp +++ b/layers/selections/text/kpTextSelection_Paint.cpp @@ -73,12 +73,24 @@ { str = preeditString.mid (i, start - i); painter.drawText (x, y, str); - x += painter.fontMetrics ().width (str); + x += painter.fontMetrics(). +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (str); } painter.save(); str = preeditString.mid (start, length); - int width = painter.fontMetrics().width (str); + int width = painter.fontMetrics(). +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (str); if (format.background ().color () != Qt::black) { painter.save (); @@ -107,7 +119,13 @@ { str = preeditString.mid (i); painter.drawText (x, y, str); - x += painter.fontMetrics ().width (str); + x += painter.fontMetrics (). +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (str); } } @@ -224,7 +242,13 @@ QString right = str.mid(col); int x = theTextAreaRect.x(); painter.drawText(x, baseLine, left); - x += fontMetrics.width(left); + x += fontMetrics. +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (left); drawPreeditString(painter, x, baseLine, thePreeditText); painter.drawText(x, baseLine, right); diff --git a/lgpl/generic/kpColorCollection.cpp b/lgpl/generic/kpColorCollection.cpp --- a/lgpl/generic/kpColorCollection.cpp +++ b/lgpl/generic/kpColorCollection.cpp @@ -30,12 +30,15 @@ #include "kpUrlFormatter.h" -#include // kdelibs4support +#include +#include #include #include #include "kpLogCategories.h" #include +#include +#include #include #include #include @@ -122,8 +125,10 @@ bool kpColorCollection::open(const QUrl &url, QWidget *parent) { - QString tempPaletteFilePath; - if (url.isEmpty () || !KIO::NetAccess::download (url, tempPaletteFilePath, parent)) + KIO::StoredTransferJob *downloadJob = KIO::storedGet(url); + KJobWidgets::setWindow(downloadJob, parent); + + if (url.isEmpty () || !downloadJob->exec()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogMisc) << "\tcould not download"; @@ -132,26 +137,23 @@ return false; } - // sync: remember to "KIO::NetAccess::removeTempFile (tempPaletteFilePath)" in all exit paths - - QFile paletteFile(tempPaletteFilePath); - if (!paletteFile.exists() || - !paletteFile.open(QIODevice::ReadOnly)) + QBuffer paletteBuffer; + paletteBuffer.setData(downloadJob->data()); + if (paletteBuffer.data().isEmpty() || + !paletteBuffer.open(QIODevice::ReadOnly)) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogMisc) << "\tcould not open qfile"; #endif - KIO::NetAccess::removeTempFile (tempPaletteFilePath); ::CouldNotOpenDialog (url, parent); return false; } // Read first line // Expected "GIMP Palette" - QString line = QString::fromLocal8Bit(paletteFile.readLine()); + QString line = QString::fromLocal8Bit(paletteBuffer.readLine()); if (line.indexOf(QLatin1String(" Palette")) == -1) { - KIO::NetAccess::removeTempFile (tempPaletteFilePath); KMessageBox::sorry (parent, i18n ("Could not open color palette \"%1\" - unsupported format.\n" "The file may be corrupt.", @@ -162,9 +164,9 @@ QList newColorList; QString newDesc; - while( !paletteFile.atEnd() ) + while( !paletteBuffer.atEnd() ) { - line = QString::fromLocal8Bit(paletteFile.readLine()); + line = QString::fromLocal8Bit(paletteBuffer.readLine()); if (line[0] == '#') { // This is a comment line @@ -197,7 +199,6 @@ d->name.clear (); d->desc = newDesc; - KIO::NetAccess::removeTempFile (tempPaletteFilePath); return true; } @@ -287,18 +288,21 @@ kpColorCollection::saveAs(const QUrl &url, bool showOverwritePrompt, QWidget *parent) const { - if (showOverwritePrompt && - KIO::NetAccess::exists (url, KIO::NetAccess::DestinationSide/*write*/, parent)) - { - int result = KMessageBox::warningContinueCancel (parent, - i18n ("A color palette called \"%1\" already exists.\n" - "Do you want to overwrite it?", - kpUrlFormatter::PrettyFilename (url)), - QString (), - KStandardGuiItem::overwrite ()); - if (result != KMessageBox::Continue) - return false; - } + if (showOverwritePrompt) { + KIO::StatJob *statJob = KIO::stat(url, KIO::StatJob::DestinationSide, 0, KIO::HideProgressInfo); + KJobWidgets::setWindow(statJob, parent); + if (statJob->exec()) { + int result = KMessageBox::warningContinueCancel (parent, + i18n ("A color palette called \"%1\" already exists.\n" + "Do you want to overwrite it?", + kpUrlFormatter::PrettyFilename (url)), + QString (), + KStandardGuiItem::overwrite ()); + if (result != KMessageBox::Continue) + return false; + } + + } if (url.isLocalFile ()) { @@ -345,8 +349,8 @@ { // Create temporary file that is deleted when the variable goes // out of scope. - QTemporaryFile tempFile; - if (!tempFile.open ()) + QBuffer tempFile; + if (!tempFile.open (QIODevice::WriteOnly)) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogMisc) << "\treturning false because could not open tempFile"; @@ -360,14 +364,9 @@ // Collect name of temporary file now, as QTemporaryFile::fileName() // stops working after close() is called. - const QString tempFileName = tempFile.fileName (); - #if DEBUG_KP_COLOR_COLLECTION - qCDebug(kpLogMisc) << "\ttempFileName='" << tempFileName << "'"; - #endif - Q_ASSERT (!tempFileName.isEmpty ()); tempFile.close (); - if (tempFile.error () != QFile::NoError) + if (tempFile.errorString().isEmpty()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogMisc) << "\treturning false because could not close"; @@ -377,10 +376,14 @@ } // Copy local temporary file to overwrite remote. - // TODO: No one seems to know how to do this atomically - // [http://lists.kde.org/?l=kde-core-devel&m=117845162728484&w=2]. - // At least, fish:// (ssh) is definitely not atomic. - if (!KIO::NetAccess::upload (tempFileName, url, parent)) + // TODO: To do it more atomically, instead of doing a separate stat job above, + // don't pass KIO::Overwrite if we should prompt in case of overwriting + // and check the return value, and re-do the storedPut() if the user wants to overwrite + // TODO: Skip the temporary file, pass a QBuffer to ::SaveToFile() instead, + // or make it just return a QByteArray we can pass directly to KIO + KIO::StoredTransferJob *uploadJob = KIO::storedPut(tempFile.data(), url, -1, KIO::Overwrite); + KJobWidgets::setWindow(uploadJob, parent); + if (!uploadJob->exec()) { #if DEBUG_KP_COLOR_COLLECTION qCDebug(kpLogMisc) << "\treturning false because could not upload"; diff --git a/lgpl/generic/widgets/kpColorCellsBase.cpp b/lgpl/generic/widgets/kpColorCellsBase.cpp --- a/lgpl/generic/widgets/kpColorCellsBase.cpp +++ b/lgpl/generic/widgets/kpColorCellsBase.cpp @@ -426,7 +426,7 @@ << " rgba=" << (int *) d->colors [cell].rgba(); #endif Q_ASSERT (d->colors[cell].isValid()); - KColorMimeData::createDrag(d->colors[cell], this)->start(Qt::CopyAction | Qt::MoveAction); + KColorMimeData::createDrag(d->colors[cell], this)->exec(Qt::CopyAction | Qt::MoveAction); #if DEBUG_KP_COLOR_CELLS_BASE qCDebug(kpLogMisc) << "finished drag"; #endif diff --git a/mainWindow/kpMainWindow.cpp b/mainWindow/kpMainWindow.cpp --- a/mainWindow/kpMainWindow.cpp +++ b/mainWindow/kpMainWindow.cpp @@ -52,6 +52,8 @@ #include #include +#include +#include #include #include #include diff --git a/mainWindow/kpMainWindow_Edit.cpp b/mainWindow/kpMainWindow_Edit.cpp --- a/mainWindow/kpMainWindow_Edit.cpp +++ b/mainWindow/kpMainWindow_Edit.cpp @@ -500,7 +500,13 @@ it != textLines.constEnd (); ++it) { - const int w = fontMetrics.width (*it); + const int w = fontMetrics. +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (*it); if (w > width) { width = w; } diff --git a/mainWindow/kpMainWindow_File.cpp b/mainWindow/kpMainWindow_File.cpp --- a/mainWindow/kpMainWindow_File.cpp +++ b/mainWindow/kpMainWindow_File.cpp @@ -58,7 +58,8 @@ #include #include // kdelibs4support #include -#include // kdelibs4support +#include +#include #include #include #include @@ -73,7 +74,7 @@ #include "document/kpDocument.h" #include "commands/imagelib/kpDocumentMetaInfoCommand.h" #include "dialogs/imagelib/kpDocumentMetaInfoDialog.h" -#include "widgets/kpDocumentSaveOptionsWidget.h" +#include "widgets/kpDocumentSaveDialog.h" #include "pixmapfx/kpPixmapFX.h" #include "widgets/kpPrintDialogPage.h" #include "views/kpView.h" @@ -818,10 +819,8 @@ kpDocumentSaveOptions fdSaveOptions = startSaveOptions; - QStringList mimeTypes; - for (const auto &type : QImageWriter::supportedMimeTypes()) { - mimeTypes << QString::fromLatin1(type); - } + const QStringList mimeTypes = kpDocumentSaveOptions::availableMimeTypes(); + #if DEBUG_KP_MAIN_WINDOW QStringList sortedMimeTypes = mimeTypes; sortedMimeTypes.sort (); @@ -885,28 +884,19 @@ fdSaveOptions.printDebug ("\tcorrected saveOptions passed to fileDialog"); #endif - auto *saveOptionsWidget = - new kpDocumentSaveOptionsWidget (imageToBeSaved, + kpDocumentSaveDialog saveOptionsWidget ( + startURL, + imageToBeSaved, fdSaveOptions, docMetaInfo, this); + saveOptionsWidget.setWindowTitle(caption); + saveOptionsWidget.setLocalOnly(localOnly); - KFileDialog fd (QUrl (startURL), QString(), this, - saveOptionsWidget); - saveOptionsWidget->setVisualParent (&fd); - fd.setWindowTitle (caption); - fd.setOperationMode (KFileDialog::Saving); - fd.setMimeFilter (mimeTypes, fdSaveOptions.mimeType ()); - if (localOnly) { - fd.setMode (KFile::File | KFile::LocalOnly); - } - connect (&fd, &KFileDialog::filterChanged, - saveOptionsWidget, &kpDocumentSaveOptionsWidget::setMimeType); - - if ( fd.exec() == QDialog::Accepted ) + if ( saveOptionsWidget.exec() == QDialog::Accepted ) { - kpDocumentSaveOptions newSaveOptions = saveOptionsWidget->documentSaveOptions (); + kpDocumentSaveOptions newSaveOptions = saveOptionsWidget.documentSaveOptions (); #if DEBUG_KP_MAIN_WINDOW newSaveOptions.printDebug ("\tnewSaveOptions"); #endif @@ -925,7 +915,7 @@ bool shouldAllowOverwritePrompt = - (fd.selectedUrl () != QUrl (startURL) || + (saveOptionsWidget.selectedUrl () != QUrl (startURL) || newSaveOptions.mimeType () != startSaveOptions.mimeType ()); if (allowOverwritePrompt) { @@ -955,7 +945,7 @@ #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "\tselectedUrl=" << fd.selectedUrl (); #endif - return fd.selectedUrl (); + return saveOptionsWidget.selectedUrl (); } return {}; @@ -1111,9 +1101,18 @@ kpDocument *doc = nullptr; + bool comesFromUrlOrExists = false; + if (d->document->isFromURL (false/*don't bother checking exists*/)) { + comesFromUrlOrExists = true; + } else if (!oldURL.isEmpty()) { + // 0 == only check if the file exists, don't bother with file metadata + KIO::StatJob *statJob = KIO::stat(oldURL, KIO::StatJob::SourceSide, 0); + KJobWidgets::setWindow(statJob, this); + comesFromUrlOrExists = statJob->exec(); + } + // If it's _supposed to_ come from a URL or it exists - if (d->document->isFromURL (false/*don't bother checking exists*/) || - (!oldURL.isEmpty () && KIO::NetAccess::exists (oldURL, KIO::NetAccess::SourceSide/*open*/, this))) + if (comesFromUrlOrExists) { #if DEBUG_KP_MAIN_WINDOW qCDebug(kpLogMainWindow) << "kpMainWindow::slotReload() reloading from disk!"; diff --git a/mainWindow/kpMainWindow_StatusBar.cpp b/mainWindow/kpMainWindow_StatusBar.cpp --- a/mainWindow/kpMainWindow_StatusBar.cpp +++ b/mainWindow/kpMainWindow_StatusBar.cpp @@ -56,7 +56,13 @@ QLabel *label = new QLabel (sb); label->setAlignment (Qt::AlignCenter); label->setFixedHeight (label->fontMetrics ().height () + 2); - int maxWidth = label->fontMetrics ().width (QLatin1Char ('8')) * maxTextLen; + int maxWidth = label->fontMetrics (). +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (QLatin1Char ('8')) * maxTextLen; // add some margins maxWidth += label->fontMetrics ().height (); label->setFixedWidth (maxWidth); diff --git a/tools/kpTool_KeyboardEvents.cpp b/tools/kpTool_KeyboardEvents.cpp --- a/tools/kpTool_KeyboardEvents.cpp +++ b/tools/kpTool_KeyboardEvents.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include "kpLogCategories.h" diff --git a/views/kpView_Paint.cpp b/views/kpView_Paint.cpp --- a/views/kpView_Paint.cpp +++ b/views/kpView_Paint.cpp @@ -338,7 +338,7 @@ painter.setPen(Qt::black); painter.setBrush(Qt::cyan); - for (const auto &r : selResizeHandlesRegion.rects()) { + for (const QRect &r : selResizeHandlesRegion) { painter.drawRect(r); } } @@ -585,9 +585,8 @@ // It seems that e->region() is already clipped by Qt to the visible // part of the view (which could be quite small inside a scrollview). const auto& viewRegion = e->region (); - QVector rects = viewRegion.rects (); #if DEBUG_KP_VIEW_RENDERER - qCDebug(kpLogViews) << "\t#rects = " << rects.count (); + qCDebug(kpLogViews) << "\t#viewRegion rects = " << viewRegion.rectCount (); #endif // Draw all of the requested regions of the document _before_ drawing @@ -602,7 +601,7 @@ // parts of nearby grid lines (which were drawn in a previous iteration) // with document pixels. Those grid line parts are probably not going to // be redrawn, so will appear to be missing. - for (const auto &r : rects) + for (const QRect &r : viewRegion) { paintEventDrawDoc_Unclipped (r); } @@ -614,7 +613,7 @@ if ( isGridShown() ) { QPainter painter(this); - for (const auto &r : rects) + for (const QRect &r : viewRegion) paintEventDrawGridLines(&painter, r); } diff --git a/widgets/imagelib/effects/kpEffectBalanceWidget.cpp b/widgets/imagelib/effects/kpEffectBalanceWidget.cpp --- a/widgets/imagelib/effects/kpEffectBalanceWidget.cpp +++ b/widgets/imagelib/effects/kpEffectBalanceWidget.cpp @@ -75,7 +75,15 @@ m_gammaLabel = new QLabel (this); // TODO: This doesn't seem to be wide enough with some fonts so the // whole layout moves when we drag the gamma slider. - m_gammaLabel->setMinimumWidth (m_gammaLabel->fontMetrics ().width (QStringLiteral (" 10.00 "))); + + m_gammaLabel->setMinimumWidth (m_gammaLabel->fontMetrics (). +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) + horizontalAdvance +#else + width +#endif + (QStringLiteral (" 10.00 "))); + m_gammaLabel->setAlignment (m_gammaLabel->alignment () | Qt::AlignRight); auto *gammaResetPushButton = new QPushButton (i18n ("Rese&t"), this); diff --git a/widgets/kpDocumentSaveOptionsWidget.h b/widgets/kpDocumentSaveDialog.h rename from widgets/kpDocumentSaveOptionsWidget.h rename to widgets/kpDocumentSaveDialog.h --- a/widgets/kpDocumentSaveOptionsWidget.h +++ b/widgets/kpDocumentSaveDialog.h @@ -32,11 +32,12 @@ #include #include -#include +#include #include "imagelib/kpDocumentMetaInfo.h" #include "document/kpDocumentSaveOptions.h" +class KFileWidget; class QComboBox; class QImage; @@ -45,28 +46,28 @@ class QSpinBox; class QPushButton; + class kpDocumentSaveOptionsPreviewDialog; -class kpDocumentSaveOptionsWidget : public QWidget +class kpDocumentSaveDialog : public QDialog { Q_OBJECT public: - kpDocumentSaveOptionsWidget (const QImage &docPixmap, + kpDocumentSaveDialog (const QString &url, const QImage &docPixmap, const kpDocumentSaveOptions &saveOptions, const kpDocumentMetaInfo &metaInfo, QWidget *parent); - kpDocumentSaveOptionsWidget (QWidget *parent); + kpDocumentSaveDialog (QWidget *parent); private: - void init (); + void init (const QUrl &startUrl); public: - ~kpDocumentSaveOptionsWidget () override; + ~kpDocumentSaveDialog () override; + void setLocalOnly(bool localOnly); - // is usually the filedialog - void setVisualParent (QWidget *visualParent); - + const QUrl selectedUrl() const; protected: bool mimeTypeHasConfigurableColorDepth () const; @@ -128,6 +129,7 @@ protected: QWidget *m_visualParent; + KFileWidget *m_fileWidget; Mode m_mode; diff --git a/widgets/kpDocumentSaveOptionsWidget.cpp b/widgets/kpDocumentSaveDialog.cpp rename from widgets/kpDocumentSaveOptionsWidget.cpp rename to widgets/kpDocumentSaveDialog.cpp --- a/widgets/kpDocumentSaveOptionsWidget.cpp +++ b/widgets/kpDocumentSaveDialog.cpp @@ -28,7 +28,7 @@ #define DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET 0 -#include "widgets/kpDocumentSaveOptionsWidget.h" +#include "widgets/kpDocumentSaveDialog.h" #include "kpDefs.h" #include "document/kpDocument.h" @@ -41,8 +41,10 @@ #include "kpLogCategories.h" #include #include +#include #include +#include #include #include #include @@ -56,34 +58,56 @@ #include -kpDocumentSaveOptionsWidget::kpDocumentSaveOptionsWidget ( +kpDocumentSaveDialog::kpDocumentSaveDialog ( + const QString &url, const QImage &docPixmap, const kpDocumentSaveOptions &saveOptions, const kpDocumentMetaInfo &metaInfo, QWidget *parent) - : QWidget (parent), - m_visualParent (parent) + : QDialog (parent) { - init (); + init (QUrl(url)); setDocumentSaveOptions (saveOptions); setDocumentPixmap (docPixmap); setDocumentMetaInfo (metaInfo); } -kpDocumentSaveOptionsWidget::kpDocumentSaveOptionsWidget ( +kpDocumentSaveDialog::kpDocumentSaveDialog ( QWidget *parent) - : QWidget (parent), - m_visualParent (parent) + : QDialog (parent) { - init (); + init (QUrl()); } // private -void kpDocumentSaveOptionsWidget::init () +void kpDocumentSaveDialog::init (const QUrl &startUrl) { + setLayout(new QVBoxLayout); + + m_fileWidget = new KFileWidget(startUrl); + m_fileWidget->setOperationMode( KFileWidget::Saving ); + m_fileWidget->setMode( KFile::Files | KFile::Directory ); + + connect(m_fileWidget, &KFileWidget::accepted, [&]() { + m_fileWidget->accept(); + + // We have to do this manually for some reason + accept(); + }); + connect (m_fileWidget, &KFileWidget::filterChanged, this, &kpDocumentSaveDialog::setMimeType); + + layout()->addWidget(m_fileWidget); + + // Normal file dialog buttons + QDialogButtonBox *buttonBox = new QDialogButtonBox; + buttonBox->addButton(m_fileWidget->okButton(), QDialogButtonBox::AcceptRole); + buttonBox->addButton(m_fileWidget->cancelButton(), QDialogButtonBox::RejectRole); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + connect(buttonBox, &QDialogButtonBox::accepted, m_fileWidget, &KFileWidget::slotOk); + layout()->addWidget(buttonBox); + m_documentPixmap = nullptr; m_previewDialog = nullptr; - m_visualParent = nullptr; m_colorDepthLabel = new QLabel (i18n ("Convert &to:"), this); @@ -107,35 +131,44 @@ m_qualityLabel->setBuddy (m_qualityInput); + QWidget *optionsWidget = new QWidget(this); + QHBoxLayout *optionsLayout = new QHBoxLayout; + optionsLayout->addSpacerItem(new QSpacerItem(0, 30)); + optionsWidget->setLayout(optionsLayout); + optionsLayout->setContentsMargins(0, 0, 0, 0); - auto *lay = new QHBoxLayout (this); - lay->setContentsMargins(0, 0, 0, 0); + optionsLayout->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); + optionsLayout->addWidget (m_colorDepthCombo, 0/*stretch*/); - lay->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); - lay->addWidget (m_colorDepthCombo, 0/*stretch*/); + optionsLayout->addWidget (m_colorDepthSpaceWidget, 1/*stretch*/); - lay->addWidget (m_colorDepthSpaceWidget, 1/*stretch*/); + optionsLayout->addWidget (m_qualityLabel, 0/*stretch*/, Qt::AlignLeft); + optionsLayout->addWidget (m_qualityInput, 2/*stretch*/); - lay->addWidget (m_qualityLabel, 0/*stretch*/, Qt::AlignLeft); - lay->addWidget (m_qualityInput, 2/*stretch*/); + optionsLayout->addWidget (m_previewButton, 0/*stretch*/, Qt::AlignRight); - lay->addWidget (m_previewButton, 0/*stretch*/, Qt::AlignRight); + // I don't like the default position it gets, so just do it old style +// buttonBox->addButton(m_previewButton, QDialogButtonBox::ApplyRole); + m_fileWidget->setCustomWidget(QString(), optionsWidget); + // To make the "automatically select extension" checkbox appear below the file type selection +// m_fileWidget->setCustomWidget(optionsWidget); + connect (m_colorDepthCombo, static_cast(&QComboBox::activated), - this, &kpDocumentSaveOptionsWidget::slotColorDepthSelected); + this, &kpDocumentSaveDialog::slotColorDepthSelected); connect (m_colorDepthCombo, static_cast(&QComboBox::activated), - this, &kpDocumentSaveOptionsWidget::updatePreview); + this, &kpDocumentSaveDialog::updatePreview); connect (m_qualityInput, static_cast(&QSpinBox::valueChanged), - this, &kpDocumentSaveOptionsWidget::updatePreviewDelayed); + this, &kpDocumentSaveDialog::updatePreviewDelayed); connect (m_previewButton, &QPushButton::toggled, - this, &kpDocumentSaveOptionsWidget::showPreview); + this, &kpDocumentSaveDialog::showPreview); m_updatePreviewDelay = 200/*ms*/; @@ -143,70 +176,73 @@ m_updatePreviewTimer = new QTimer (this); m_updatePreviewTimer->setSingleShot (true); connect (m_updatePreviewTimer, &QTimer::timeout, - this, &kpDocumentSaveOptionsWidget::updatePreview); + this, &kpDocumentSaveDialog::updatePreview); m_updatePreviewDialogLastRelativeGeometryTimer = new QTimer (this); connect (m_updatePreviewDialogLastRelativeGeometryTimer, &QTimer::timeout, - this, &kpDocumentSaveOptionsWidget::updatePreviewDialogLastRelativeGeometry); + this, &kpDocumentSaveDialog::updatePreviewDialogLastRelativeGeometry); setMode (None); slotColorDepthSelected (); } -kpDocumentSaveOptionsWidget::~kpDocumentSaveOptionsWidget () +kpDocumentSaveDialog::~kpDocumentSaveDialog () { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::()"; + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::()"; #endif hidePreview (); delete m_documentPixmap; } - -// public -void kpDocumentSaveOptionsWidget::setVisualParent (QWidget *visualParent) +void kpDocumentSaveDialog::setLocalOnly(bool localOnly) { -#if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setVisualParent(" - << visualParent << ")" << endl; -#endif - - m_visualParent = visualParent; + if (localOnly) { + m_fileWidget->setMode (KFile::File | KFile::LocalOnly); + } else { + m_fileWidget->setMode (KFile::File); + } } +const QUrl kpDocumentSaveDialog::selectedUrl() const +{ + return m_fileWidget->selectedUrl(); +} // protected -bool kpDocumentSaveOptionsWidget::mimeTypeHasConfigurableColorDepth () const +bool kpDocumentSaveDialog::mimeTypeHasConfigurableColorDepth () const { return kpDocumentSaveOptions::mimeTypeHasConfigurableColorDepth (mimeType ()); } // protected -bool kpDocumentSaveOptionsWidget::mimeTypeHasConfigurableQuality () const +bool kpDocumentSaveDialog::mimeTypeHasConfigurableQuality () const { return kpDocumentSaveOptions::mimeTypeHasConfigurableQuality (mimeType ()); } // public -QString kpDocumentSaveOptionsWidget::mimeType () const +QString kpDocumentSaveDialog::mimeType () const { return m_baseDocumentSaveOptions.mimeType (); } // public slots -void kpDocumentSaveOptionsWidget::setMimeType (const QString &string) +void kpDocumentSaveDialog::setMimeType (const QString &string) { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setMimeType(" << string + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::setMimeType(" << string << ") maxColorDepth=" << kpDocumentSaveOptions::mimeTypeMaximumColorDepth (string) << endl; #endif + m_fileWidget->setMimeFilter(kpDocumentSaveOptions::availableMimeTypes(), string); + const int newMimeTypeMaxDepth = kpDocumentSaveOptions::mimeTypeMaximumColorDepth (string); @@ -279,7 +315,7 @@ // public -int kpDocumentSaveOptionsWidget::colorDepth () const +int kpDocumentSaveDialog::colorDepth () const { if (mode () & ColorDepth) { @@ -309,7 +345,7 @@ } // public -bool kpDocumentSaveOptionsWidget::dither () const +bool kpDocumentSaveDialog::dither () const { if (mode () & ColorDepth) { @@ -321,7 +357,7 @@ } // protected static -int kpDocumentSaveOptionsWidget::colorDepthComboItemFromColorDepthAndDither ( +int kpDocumentSaveDialog::colorDepthComboItemFromColorDepthAndDither ( int depth, bool dither) { switch (depth) { @@ -346,10 +382,10 @@ } // public slots -void kpDocumentSaveOptionsWidget::setColorDepthDither (int newDepth, bool newDither) +void kpDocumentSaveDialog::setColorDepthDither (int newDepth, bool newDither) { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setColorDepthDither(" + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::setColorDepthDither(" << "depth=" << newDepth << ",dither=" << newDither << ")" << endl; @@ -375,7 +411,7 @@ // protected slot -void kpDocumentSaveOptionsWidget::slotColorDepthSelected () +void kpDocumentSaveDialog::slotColorDepthSelected () { if (mode () & ColorDepth) { @@ -390,7 +426,7 @@ } #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::slotColorDepthSelected()" + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::slotColorDepthSelected()" << " mode&ColorDepth=" << (mode () & ColorDepth) << " colorDepthComboLastSelectedItem=" << m_colorDepthComboLastSelectedItem @@ -400,7 +436,7 @@ // public -int kpDocumentSaveOptionsWidget::quality () const +int kpDocumentSaveDialog::quality () const { if (mode () & Quality) { @@ -411,10 +447,10 @@ } // public -void kpDocumentSaveOptionsWidget::setQuality (int newQuality) +void kpDocumentSaveDialog::setQuality (int newQuality) { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::setQuality(" + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::setQuality(" << newQuality << ")" << endl; #endif @@ -426,13 +462,13 @@ // public -kpDocumentSaveOptions kpDocumentSaveOptionsWidget::documentSaveOptions () const +kpDocumentSaveOptions kpDocumentSaveDialog::documentSaveOptions () const { return kpDocumentSaveOptions (mimeType (), colorDepth (), dither (), quality ()); } // public -void kpDocumentSaveOptionsWidget::setDocumentSaveOptions ( +void kpDocumentSaveDialog::setDocumentSaveOptions ( const kpDocumentSaveOptions &saveOptions) { setMimeType (saveOptions.mimeType ()); @@ -442,7 +478,7 @@ // public -void kpDocumentSaveOptionsWidget::setDocumentPixmap (const QImage &documentPixmap) +void kpDocumentSaveDialog::setDocumentPixmap (const QImage &documentPixmap) { delete m_documentPixmap; m_documentPixmap = new QImage (documentPixmap); @@ -451,7 +487,7 @@ } // public -void kpDocumentSaveOptionsWidget::setDocumentMetaInfo ( +void kpDocumentSaveDialog::setDocumentMetaInfo ( const kpDocumentMetaInfo &metaInfo) { m_documentMetaInfo = metaInfo; @@ -461,13 +497,13 @@ // public -kpDocumentSaveOptionsWidget::Mode kpDocumentSaveOptionsWidget::mode () const +kpDocumentSaveDialog::Mode kpDocumentSaveDialog::mode () const { return m_mode; } // public -void kpDocumentSaveOptionsWidget::setMode (Mode mode) +void kpDocumentSaveDialog::setMode (Mode mode) { m_mode = mode; @@ -492,11 +528,11 @@ // we change the height of "this", causing the text on the labels // to move but the first instance of the text doesn't get erased. // Qt bug. - QTimer::singleShot (0, this, &kpDocumentSaveOptionsWidget::repaintLabels); + QTimer::singleShot (0, this, &kpDocumentSaveDialog::repaintLabels); } // protected slot -void kpDocumentSaveOptionsWidget::repaintLabels () +void kpDocumentSaveDialog::repaintLabels () { if (mode () != Quality) { m_colorDepthLabel->repaint (); @@ -508,10 +544,10 @@ // protected slot -void kpDocumentSaveOptionsWidget::showPreview (bool yes) +void kpDocumentSaveDialog::showPreview (bool yes) { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::showPreview(" << yes << ")" + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::showPreview(" << yes << ")" << " m_previewDialog=" << bool (m_previewDialog) << endl; #endif @@ -520,18 +556,14 @@ return; } - if (!m_visualParent) { - return; - } - if (yes) { - m_previewDialog = new kpDocumentSaveOptionsPreviewDialog( m_visualParent ); + m_previewDialog = new kpDocumentSaveOptionsPreviewDialog( this ); m_previewDialog->setObjectName( QStringLiteral( "previewSaveDialog" ) ); updatePreview (); connect (m_previewDialog, &kpDocumentSaveOptionsPreviewDialog::finished, - this, &kpDocumentSaveOptionsWidget::hidePreview); + this, &kpDocumentSaveDialog::hidePreview); KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupPreviewSave); @@ -568,13 +600,13 @@ #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET qCDebug(kpLogWidgets) << "\tpreviewDialogLastRelativeGeometry=" << m_previewDialogLastRelativeGeometry - << " visualParent->rect()=" << m_visualParent->rect () + << " this->rect()=" << this->rect () << endl; #endif QRect relativeGeometry; if (!m_previewDialogLastRelativeGeometry.isEmpty () && - m_visualParent->rect ().intersects (m_previewDialogLastRelativeGeometry)) + this->rect ().intersects (m_previewDialogLastRelativeGeometry)) { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET qCDebug(kpLogWidgets) << "\tok"; @@ -589,7 +621,7 @@ const int margin = 20; relativeGeometry = - QRect (m_visualParent->width () - + QRect (this->width () - m_previewDialog->preferredMinimumSize ().width () - margin, margin * 2, // Avoid folder combo @@ -599,7 +631,7 @@ const QRect globalGeometry = - kpWidgetMapper::toGlobal (m_visualParent, + kpWidgetMapper::toGlobal (this, relativeGeometry); #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET qCDebug(kpLogWidgets) << "\trelativeGeometry=" << relativeGeometry @@ -624,10 +656,10 @@ updatePreviewDialogLastRelativeGeometry (); connect (m_previewDialog, &kpDocumentSaveOptionsPreviewDialog::moved, - this, &kpDocumentSaveOptionsWidget::updatePreviewDialogLastRelativeGeometry); + this, &kpDocumentSaveDialog::updatePreviewDialogLastRelativeGeometry); connect (m_previewDialog, &kpDocumentSaveOptionsPreviewDialog::resized, - this, &kpDocumentSaveOptionsWidget::updatePreviewDialogLastRelativeGeometry); + this, &kpDocumentSaveDialog::updatePreviewDialogLastRelativeGeometry); m_updatePreviewDialogLastRelativeGeometryTimer->start (200/*ms*/); } @@ -644,7 +676,7 @@ qCDebug(kpLogWidgets) << "\tsaving preview geometry " << m_previewDialogLastRelativeGeometry << " (Qt would have us believe " - << kpWidgetMapper::fromGlobal (m_visualParent, + << kpWidgetMapper::fromGlobal (this, QRect (m_previewDialog->x (), m_previewDialog->y (), m_previewDialog->width (), m_previewDialog->height ())) << ")" @@ -657,7 +689,7 @@ } // protected slot -void kpDocumentSaveOptionsWidget::hidePreview () +void kpDocumentSaveDialog::hidePreview () { if (m_previewButton->isChecked ()) { m_previewButton->toggle (); @@ -666,14 +698,14 @@ // protected slot -void kpDocumentSaveOptionsWidget::updatePreviewDelayed () +void kpDocumentSaveDialog::updatePreviewDelayed () { // (single shot) m_updatePreviewTimer->start (m_updatePreviewDelay); } // protected slot -void kpDocumentSaveOptionsWidget::updatePreview () +void kpDocumentSaveDialog::updatePreview () { if (!m_previewDialog || !m_documentPixmap) { return; @@ -724,10 +756,10 @@ } // protected slot -void kpDocumentSaveOptionsWidget::updatePreviewDialogLastRelativeGeometry () +void kpDocumentSaveDialog::updatePreviewDialogLastRelativeGeometry () { #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET - qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::" + qCDebug(kpLogWidgets) << "kpDocumentSaveDialog::" << "updatePreviewDialogLastRelativeGeometry()" << endl; #endif @@ -735,7 +767,7 @@ if (m_previewDialog && m_previewDialog->isVisible ()) { m_previewDialogLastRelativeGeometry = - kpWidgetMapper::fromGlobal (m_visualParent, + kpWidgetMapper::fromGlobal (this, QRect (m_previewDialog->x (), m_previewDialog->y (), m_previewDialog->width (), m_previewDialog->height ())); #if DEBUG_KP_DOCUMENT_SAVE_OPTIONS_WIDGET