From: Mike Gelfand Date: Sat, 11 Feb 2017 10:44:34 +0000 (+0300) Subject: Remove supporting code for Qt < 5.2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03034b501563a9900f67ce4cb68b9535c629cfbf;p=transmission Remove supporting code for Qt < 5.2 --- diff --git a/qt/Application.cc b/qt/Application.cc index 4051bb583..e76d79828 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -97,10 +97,6 @@ Application::Application (int& argc, char ** argv): Formatter::initUnits (); -#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) - setAttribute (Qt::AA_UseHighDpiPixmaps); -#endif - #if defined (_WIN32) || defined (__APPLE__) if (QIcon::themeName ().isEmpty ()) QIcon::setThemeName (QLatin1String ("Faenza")); @@ -310,12 +306,7 @@ Application::loadTranslations () #endif (applicationDirPath () + QLatin1String ("/translations")); - const QString qtFileName = -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QLatin1String ("qt"); -#else - QLatin1String ("qtbase"); -#endif + const QString qtFileName = QLatin1String ("qtbase"); const QLocale locale; const QLocale englishLocale (QLocale::English, QLocale::UnitedStates); @@ -589,7 +580,10 @@ tr_main (int argc, { InteropHelper::initialize (); +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) Application::setAttribute (Qt::AA_EnableHighDpiScaling); +#endif + Application::setAttribute (Qt::AA_UseHighDpiPixmaps); Application app (argc, argv); diff --git a/qt/CMakeLists.txt b/qt/CMakeLists.txt index 23c085250..0ce72385c 100644 --- a/qt/CMakeLists.txt +++ b/qt/CMakeLists.txt @@ -16,7 +16,6 @@ set(${PROJECT_NAME}_SOURCES FilterBar.cc FilterBarComboBox.cc FilterBarComboBoxDelegate.cc - FilterBarLineEdit.cc Filters.cc Formatter.cc FreeSpaceLabel.cc @@ -76,7 +75,6 @@ set(${PROJECT_NAME}_HEADERS FilterBar.h FilterBarComboBox.h FilterBarComboBoxDelegate.h - FilterBarLineEdit.h Filters.h Formatter.h FreeSpaceLabel.h diff --git a/qt/FaviconCache.cc b/qt/FaviconCache.cc index 420d72450..3025107f2 100644 --- a/qt/FaviconCache.cc +++ b/qt/FaviconCache.cc @@ -10,12 +10,7 @@ #include #include #include - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - #include -#else - #include -#endif +#include #include "FaviconCache.h" @@ -41,12 +36,7 @@ FaviconCache::~FaviconCache () QString FaviconCache::getCacheDir () { - const QString base = -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - QDesktopServices::storageLocation (QDesktopServices::CacheLocation); -#else - QStandardPaths::writableLocation (QStandardPaths::CacheLocation); -#endif + const QString base = QStandardPaths::writableLocation (QStandardPaths::CacheLocation); return QDir(base).absoluteFilePath (QLatin1String ("favicons")); } diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index d84b3d17a..21f36573a 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include "Application.h" @@ -16,7 +17,6 @@ #include "FilterBar.h" #include "FilterBarComboBox.h" #include "FilterBarComboBoxDelegate.h" -#include "FilterBarLineEdit.h" #include "Prefs.h" #include "Torrent.h" #include "TorrentFilter.h" @@ -241,7 +241,9 @@ FilterBar::FilterBar (Prefs& prefs, const TorrentModel& torrents, const TorrentF h->addStretch (); - myLineEdit = new FilterBarLineEdit (this); + myLineEdit = new QLineEdit (this); + myLineEdit->setClearButtonEnabled (true); + myLineEdit->setPlaceholderText (tr ("Search...")); myLineEdit->setMaximumWidth (250); h->addWidget (myLineEdit, 1); connect (myLineEdit, SIGNAL (textChanged (QString)), this, SLOT (onTextChanged (QString))); diff --git a/qt/FilterBar.h b/qt/FilterBar.h index 0f957376f..fda9ffae0 100644 --- a/qt/FilterBar.h +++ b/qt/FilterBar.h @@ -11,11 +11,11 @@ #include class QLabel; +class QLineEdit; class QStandardItemModel; class QTimer; class FilterBarComboBox; -class FilterBarLineEdit; class Prefs; class TorrentFilter; class TorrentModel; @@ -56,6 +56,6 @@ class FilterBar: public QWidget QStandardItemModel * myTrackerModel; QTimer * myRecountTimer; bool myIsBootstrapping; - FilterBarLineEdit * myLineEdit; + QLineEdit * myLineEdit; }; diff --git a/qt/FilterBarLineEdit.cc b/qt/FilterBarLineEdit.cc deleted file mode 100644 index 0dff16065..000000000 --- a/qt/FilterBarLineEdit.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file Copyright (C) 2012-2015 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - */ - -#include -#include - -#include "FilterBarLineEdit.h" - -FilterBarLineEdit::FilterBarLineEdit (QWidget * parent): - QLineEdit (parent), - myClearButton (nullptr) -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const QIcon icon = QIcon::fromTheme (QLatin1String ("edit-clear"), style ()->standardIcon (QStyle::SP_DialogCloseButton)); - const int iconSize = style ()->pixelMetric (QStyle::PM_SmallIconSize); - - myClearButton = new QToolButton (this); - myClearButton->setStyleSheet (QLatin1String ("QToolButton{border:0;padding:0;margin:0}")); - myClearButton->setToolButtonStyle (Qt::ToolButtonIconOnly); - myClearButton->setFocusPolicy (Qt::NoFocus); - myClearButton->setCursor (Qt::ArrowCursor); - myClearButton->setIconSize (QSize (iconSize, iconSize)); - myClearButton->setIcon (icon); - myClearButton->setFixedSize (myClearButton->iconSize () + QSize (2, 2)); - myClearButton->hide (); - - const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); - const QSize minSizeHint = minimumSizeHint (); - const QSize buttonSize = myClearButton->size (); - - setStyleSheet (QString::fromLatin1 ("QLineEdit{padding-right:%1px}").arg (buttonSize.width () + frameWidth + 1)); - setMinimumSize (qMax (minSizeHint.width (), buttonSize.width () + frameWidth * 2 + 2), - qMax (minSizeHint.height (), buttonSize.height () + frameWidth * 2 + 2)); - - connect (this, SIGNAL (textChanged (QString)), this, SLOT (updateClearButtonVisibility ())); - connect (myClearButton, SIGNAL (clicked ()), this, SLOT (clear ())); -#else - setClearButtonEnabled (true); -#endif - -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - setPlaceholderText (tr ("Search...")); -#endif -} - -void -FilterBarLineEdit::resizeEvent (QResizeEvent * event) -{ - QLineEdit::resizeEvent (event); - -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); - const QRect editRect = rect(); - const QSize buttonSize = myClearButton->size (); - - myClearButton->move (editRect.right () - frameWidth - buttonSize.width (), - editRect.top () + (editRect.height () - buttonSize.height ()) / 2); -#endif -} - -void -FilterBarLineEdit::updateClearButtonVisibility () -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 2, 0) - myClearButton->setVisible (!text ().isEmpty ()); -#endif -} diff --git a/qt/FilterBarLineEdit.h b/qt/FilterBarLineEdit.h deleted file mode 100644 index 814e18053..000000000 --- a/qt/FilterBarLineEdit.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file Copyright (C) 2010-2015 Mnemosyne LLC - * - * It may be used under the GNU GPL versions 2 or 3 - * or any future license endorsed by Mnemosyne LLC. - * - */ - -#pragma once - -#include - -class QToolButton; - -class FilterBarLineEdit: public QLineEdit -{ - Q_OBJECT - - public: - FilterBarLineEdit (QWidget * parent = nullptr); - - protected: - // QWidget - virtual void resizeEvent (QResizeEvent * event); - - private slots: - void updateClearButtonVisibility (); - - private: - QToolButton * myClearButton; -}; - diff --git a/qt/RpcClient.cc b/qt/RpcClient.cc index 25795b5b9..43b031593 100644 --- a/qt/RpcClient.cc +++ b/qt/RpcClient.cc @@ -86,14 +86,8 @@ RpcClient::isLocal () const if (mySession != 0) return true; -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - if (myUrl.host () == QLatin1String ("127.0.0.1") || - myUrl.host ().compare (QLatin1String ("localhost"), Qt::CaseInsensitive) == 0) - return true; -#else if (QHostAddress (myUrl.host ()).isLoopback ()) return true; -#endif return false; } diff --git a/qt/Utils.cc b/qt/Utils.cc index ac67bbcc6..8c097a1df 100644 --- a/qt/Utils.cc +++ b/qt/Utils.cc @@ -21,16 +21,13 @@ #include #include #include +#include +#include #include #include #include #include -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) -#include -#include -#endif - #include #include // tr_formatter @@ -40,7 +37,7 @@ **** ***/ -#if defined(_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#if defined(_WIN32) // Should be in QtWinExtras soon, but for now let's import it manually extern QPixmap qt_pixmapFromWinHICON(HICON icon); #endif @@ -68,11 +65,7 @@ namespace { if (shellFileInfo.hIcon != NULL) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) pixmap = qt_pixmapFromWinHICON (shellFileInfo.hIcon); -#else - pixmap = QPixmap::fromWinHICON (shellFileInfo.hIcon); -#endif ::DestroyIcon (shellFileInfo.hIcon); } } @@ -113,69 +106,13 @@ Utils::guessMimeIcon (const QString& filename) if (!icon.isNull ()) return icon; -#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#else QMimeDatabase mimeDb; QMimeType mimeType = mimeDb.mimeTypeForFile (filename, QMimeDatabase::MatchExtension); if (mimeType.isValid ()) return QIcon::fromTheme (mimeType.iconName (), QIcon::fromTheme (mimeType.genericIconName (), fallback)); -#else - - enum { DISK, DOCUMENT, PICTURE, VIDEO, ARCHIVE, AUDIO, APP, TYPE_COUNT }; - static QIcon fileIcons[TYPE_COUNT]; - static QSet suffixes[TYPE_COUNT]; - - if (fileIcons[0].isNull ()) - { - suffixes[DISK] << QString::fromLatin1("iso"); - fileIcons[DISK]= QIcon::fromTheme (QString::fromLatin1("media-optical"), fallback); - - const char * doc_types[] = { - "abw", "csv", "doc", "dvi", "htm", "html", "ini", "log", "odp", - "ods", "odt", "pdf", "ppt", "ps", "rtf", "tex", "txt", "xml" }; - for (const char * t: doc_types) - suffixes[DOCUMENT] << QString::fromLatin1(t); - fileIcons[DOCUMENT] = QIcon::fromTheme (QString::fromLatin1("text-x-generic"), fallback); - - const char * pic_types[] = { - "bmp", "gif", "jpg", "jpeg", "pcx", "png", "psd", "ras", "tga", "tiff" }; - for (const char * t: pic_types) - suffixes[PICTURE] << QString::fromLatin1(t); - fileIcons[PICTURE] = QIcon::fromTheme (QString::fromLatin1("image-x-generic"), fallback); - - const char * vid_types[] = { - "3gp", "asf", "avi", "mkv", "mov", "mpeg", "mpg", "mp4", - "ogm", "ogv", "qt", "rm", "wmv" }; - for (const char * t: vid_types) - suffixes[VIDEO] << QString::fromLatin1(t); - fileIcons[VIDEO] = QIcon::fromTheme (QString::fromLatin1("video-x-generic"), fallback); - - const char * arc_types[] = { - "7z", "ace", "bz2", "cbz", "gz", "gzip", "lzma", "rar", "sft", "tar", "zip" }; - for (const char * t: arc_types) - suffixes[ARCHIVE] << QString::fromLatin1(t); - fileIcons[ARCHIVE] = QIcon::fromTheme (QString::fromLatin1("package-x-generic"), fallback); - - const char * aud_types[] = { - "aac", "ac3", "aiff", "ape", "au", "flac", "m3u", "m4a", "mid", "midi", "mp2", - "mp3", "mpc", "nsf", "oga", "ogg", "ra", "ram", "shn", "voc", "wav", "wma" }; - for (const char * t: aud_types) - suffixes[AUDIO] << QString::fromLatin1(t); - fileIcons[AUDIO] = QIcon::fromTheme (QString::fromLatin1("audio-x-generic"), fallback); - - const char * exe_types[] = { "bat", "cmd", "com", "exe" }; - for (const char * t: exe_types) - suffixes[APP] << QString::fromLatin1(t); - fileIcons[APP] = QIcon::fromTheme (QString::fromLatin1("application-x-executable"), fallback); - } - - QString suffix (QFileInfo (filename).suffix ().toLower ()); - - for (int i=0; i