diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index bcd3d602..94cfcc89 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -29,15 +29,6 @@ jobs: uses: jurplel/install-qt-action@v3 with: version: ${{env.QT_VERSION}} - - name: Install Adwaita-qt - run: | - git clone https://github.com/FedoraQt/adwaita-qt.git adwaita-qt - cd adwaita-qt - mkdir build - cd build - cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT6=ON - make -j2 - sudo make install - name: Build run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 11fec105..ccff6c8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,10 +39,6 @@ endif() find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED Core DBus Gui Network Svg Qml Quick QuickControls2 Widgets) -if (UNIX AND NOT APPLE) - find_package(AdwaitaQt6 "1.4.2" REQUIRED) -endif() - add_subdirectory(src) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/dist/fedora/mediawriter.spec b/dist/fedora/mediawriter.spec index cdff3d6a..99e59efd 100644 --- a/dist/fedora/mediawriter.spec +++ b/dist/fedora/mediawriter.spec @@ -15,7 +15,6 @@ BuildRequires: gettext BuildRequires: cmake BuildRequires: make BuildRequires: libappstream-glib -BuildRequires: libadwaita-qt6-devel BuildRequires: qt6-qtbase-devel BuildRequires: qt6-qtdeclarative-devel BuildRequires: xz-devel @@ -43,9 +42,6 @@ like flash drives or memory cards. %prep %autosetup -p1 -n MediaWriter-%{version} -# Install the theme into correct prefix when building for /app -sed -i 's@\${QT6_INSTALL_QML}@%{_qt6_qmldir}@' src/theme/CMakeLists.txt - %build %cmake @@ -71,9 +67,6 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/org.fedo %{_datadir}/icons/hicolor/128x128/apps/org.fedoraproject.MediaWriter.png %{_datadir}/icons/hicolor/256x256/apps/org.fedoraproject.MediaWriter.png %{_datadir}/icons/hicolor/512x512/apps/org.fedoraproject.MediaWriter.png -%{_qt6_qmldir}/QtQuick/Controls/org/fedoraproject/AdwaitaTheme/ -%{_qt6_qmldir}/org/fedoraproject/AdwaitaTheme/libadwaitathemeplugin.so -%{_qt6_qmldir}/org/fedoraproject/AdwaitaTheme/qmldir %changelog * Mon May 09 06 2022 Jan Grulich - 5.0.0-1 diff --git a/dist/flatpak/fmw-paths.patch b/dist/flatpak/fmw-paths.patch deleted file mode 100644 index 84392a8a..00000000 --- a/dist/flatpak/fmw-paths.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/src/theme/CMakeLists.txt b/src/theme/CMakeLists.txt -index de208fd..7291536 100644 ---- a/src/theme/CMakeLists.txt -+++ b/src/theme/CMakeLists.txt -@@ -23,6 +23,6 @@ target_link_libraries(adwaitathemeplugin - ${ADWAITAQT_LIBRARIES} - ) - --install(TARGETS adwaitathemeplugin DESTINATION ${QT6_INSTALL_QML}/org/fedoraproject/AdwaitaTheme) --install(FILES qmldir DESTINATION ${QT6_INSTALL_QML}/org/fedoraproject/AdwaitaTheme) --install(DIRECTORY qml/ DESTINATION ${QT6_INSTALL_QML}/QtQuick/Controls/org/fedoraproject/AdwaitaTheme) -+install(TARGETS adwaitathemeplugin DESTINATION /app/lib/qt6/qml/org/fedoraproject/AdwaitaTheme) -+install(FILES qmldir DESTINATION /app/lib/qt6/qml/org/fedoraproject/AdwaitaTheme) -+install(DIRECTORY qml/ DESTINATION /app/lib/qt6/qml/QtQuick/Controls/org/fedoraproject/AdwaitaTheme) diff --git a/dist/flatpak/org.fedoraproject.MediaWriter.json b/dist/flatpak/org.fedoraproject.MediaWriter.json index 8ee75c28..1146bfce 100644 --- a/dist/flatpak/org.fedoraproject.MediaWriter.json +++ b/dist/flatpak/org.fedoraproject.MediaWriter.json @@ -21,24 +21,6 @@ "/lib/pkgconfig" ], "modules": [ - { - "name": "Adwaita-qt", - "buildsystem": "cmake", - "config-opts": ["-DUSE_QT6=ON"], - "sources": [ - { - "type": "git", - "url": "https://github.com/FedoraQt/adwaita-qt.git", - "tag": "1.4.2" - }, - { - "type": "shell", - "commands": [ - "sed -i 's@add_subdirectory(style)@#add_subdirectory(style)@' src/CMakeLists.txt" - ] - } - ] - }, { "name": "MediaWriter", "buildsystem": "cmake", @@ -47,10 +29,6 @@ "type": "git", "url": "https://github.com/FedoraQt/MediaWriter.git", "branch": "main" - }, - { - "type": "patch", - "path": "fmw-paths.patch" } ] } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7b1b2c54..262304c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,3 @@ add_subdirectory(helper) add_subdirectory(app) add_subdirectory(lib) -if (UNIX AND NOT APPLE) - add_subdirectory(theme) -endif() diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index cf869e0a..2442b343 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,8 +1,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/lib - ${CMAKE_SOURCE_DIR}/src/theme - ${ADWAITAQT_INCLUDE_DIRS} ) set(MEDIAWRITER_SRCS @@ -17,8 +15,6 @@ set(MEDIAWRITER_SRCS units.cpp utilities.cpp versionchecker.cpp - # From theme - ${CMAKE_SOURCE_DIR}/src/theme/icon.cpp ) if (UNIX AND NOT APPLE) @@ -81,7 +77,6 @@ target_link_libraries(mediawriter if (UNIX AND NOT APPLE) target_link_libraries(mediawriter Qt6::DBus - ${ADWAITAQT_LIBRARIES} ) endif() diff --git a/src/app/main.cpp b/src/app/main.cpp index 5ea11304..6b7b0efa 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -31,16 +31,11 @@ #include "crashhandler.h" #include "drivemanager.h" -#include "icon.h" #include "portalfiledialog.h" #include "releasemanager.h" #include "units.h" #include "versionchecker.h" -#if (defined(__linux)) -#include -#endif - #ifdef QT_STATIC Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); @@ -74,10 +69,6 @@ int main(int argc, char **argv) QApplication::setOrganizationName("fedoraproject.org"); QApplication::setApplicationName("MediaWriter"); -#if (defined(__linux)) - QQuickStyle::setStyle("QtQuick.Controls.org.fedoraproject.AdwaitaTheme"); -#endif - QApplication app(argc, argv); options.parse(app.arguments()); @@ -87,10 +78,6 @@ int main(int argc, char **argv) if (translator.load(QLocale(QLocale().language(), QLocale().country()), QLatin1String(), QLatin1String(), ":/translations")) app.installTranslator(&translator); -#if (defined(__linux)) - QPalette adwaitaPalette = Adwaita::Colors::palette(); - QGuiApplication::setPalette(adwaitaPalette); -#endif QGuiApplication::setDesktopFileName("org.fedoraproject.MediaWriter.desktop"); mDebug() << "Injecting QML context properties"; @@ -109,8 +96,6 @@ int main(int argc, char **argv) engine.rootContext()->setContextProperty("platformSupportsDelayedWriting", false); #endif - qmlRegisterType("MediaWriter", 1, 0, "Icon"); - mDebug() << "Loading the QML source code"; engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); diff --git a/src/app/qml/AboutDialog.qml b/src/app/qml/AboutDialog.qml index 8a717b79..f74b45d7 100644 --- a/src/app/qml/AboutDialog.qml +++ b/src/app/qml/AboutDialog.qml @@ -92,7 +92,7 @@ ApplicationWindow { Button { id: closeButton onClicked: aboutDialog.close() - text: qsTr("Close") + text: qsTr("&Close") } } } diff --git a/src/app/qml/CancelDialog.qml b/src/app/qml/CancelDialog.qml index 933c8a82..f42f2392 100644 --- a/src/app/qml/CancelDialog.qml +++ b/src/app/qml/CancelDialog.qml @@ -85,7 +85,7 @@ ApplicationWindow { Button { id: continueButton onClicked: cancelDialog.close() - text: qsTr("Continue") + text: qsTr("C&ontinue") } Button { @@ -108,13 +108,13 @@ ApplicationWindow { } text: { if (releases.variant.status == Units.DownloadStatus.Downloading || releases.variant.status === Units.DownloadStatus.Download_Verifying) - qsTr("Cancel Download") + qsTr("&Cancel Download") else if (releases.variant.status == Units.DownloadStatus.Writing) - qsTr("Cancel Writing") + qsTr("&Cancel Writing") else if (releases.variant.status == Units.DownloadStatus.Write_Verifying) - qsTr("Cancel Verification") + qsTr("&Cancel Verification") else - qsTr("Cancel") + qsTr("&Cancel") } } } diff --git a/src/app/qml/main.qml b/src/app/qml/main.qml index 5a2e228d..14e4b066 100644 --- a/src/app/qml/main.qml +++ b/src/app/qml/main.qml @@ -92,7 +92,6 @@ ApplicationWindow { Button { id: prevButton visible: true - text: getPrevButtonText() } Item { @@ -102,8 +101,7 @@ ApplicationWindow { Button { id: nextButton visible: mainLayout.state != "downloadPage" - enabled: mainLayout.state != "drivePage" - text: getNextButtonText() + enabled: mainLayout.state != "drivePage" } } @@ -118,7 +116,6 @@ ApplicationWindow { //When comming back from restore page, after successfull restoring a USB drive PropertyChanges { target: prevButton - text: getPrevButtonText() onClicked: aboutDialog.show() } PropertyChanges { @@ -151,9 +148,20 @@ ApplicationWindow { State { name: "versionPage" when: selectedPage == Units.Page.VersionPage - PropertyChanges { target: mainWindow; title: qsTr("Select Fedora Version") } - PropertyChanges { target: nextButton; visible: true; onClicked: selectedPage += 1 } - PropertyChanges { target: prevButton; visible: true; onClicked: selectedPage -= 1 } + PropertyChanges { + target: mainWindow + title: qsTr("Select Fedora Version") + } + PropertyChanges { + target: nextButton + visible: true + onClicked: selectedPage += 1 + } + PropertyChanges { + target: prevButton + visible: true + onClicked: selectedPage -= 1 + } StateChangeScript { script: { //state was pushing same page when returing from drivePage @@ -170,7 +178,7 @@ ApplicationWindow { title: qsTr("Select Drive") } PropertyChanges { - target: nextButton; + target: nextButton visible: true onClicked: { selectedPage = Units.Page.DownloadPage @@ -269,6 +277,11 @@ ApplicationWindow { } } ] + + onStateChanged: { + nextButton.text = getNextButtonText() + prevButton.text = getPrevButtonText() + } } Units { @@ -282,38 +295,43 @@ ApplicationWindow { CancelDialog { id: cancelDialog } - - + function getNextButtonText() { + var text = "" if (mainLayout.state == "restorePage") { if (lastRestoreable && lastRestoreable.restoreStatus == Units.RestoreStatus.Restored) - return qsTr("Finish") - return qsTr("Restore") + text = qsTr("Finish") + text = qsTr("Restore") } else if (mainLayout.state == "drivePage") { if (selectedOption == Units.MainSelect.Write || downloadManager.isDownloaded(releases.selected.version.variant.url)) - return qsTr("Write") + text = qsTr("Write") if (Qt.platform.os === "windows" || Qt.platform.os === "osx") - return qsTr("Download && Write") - return qsTr("Download & Write") + text = qsTr("Download && Write") + text = qsTr("Download & Write") } else if (mainLayout.state == "downloadPage") { if (releases.variant.status === Units.DownloadStatus.Write_Verifying || releases.variant.status === Units.DownloadStatus.Writing || releases.variant.status === Units.DownloadStatus.Downloading || releases.variant.status === Units.DownloadStatus.Download_Verifying) - return qsTr("Cancel") + text = qsTr("Cancel") else if (releases.variant.status == Units.DownloadStatus.Ready) - return qsTr("Write") + text = qsTr("Write") else if (releases.variant.status === Units.DownloadStatus.Finished) - return qsTr("Finish") + text = qsTr("Finish") else - return qsTr("Retry") + text = qsTr("Retry") } - return qsTr("Next") + else + text = qsTr("Next") + return "&" + text } function getPrevButtonText() { + var text = "" if (mainLayout.state == "mainPage") - return qsTr("About") + text = qsTr("About") else if (mainLayout.state == "downloadPage") - return qsTr("Cancel") - return qsTr("Previous") + text = qsTr("Cancel") + else + text = qsTr("Previous") + return "&" + text } } diff --git a/src/theme/CMakeLists.txt b/src/theme/CMakeLists.txt deleted file mode 100644 index 2acf32e5..00000000 --- a/src/theme/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ - -include_directories(${ADWAITAQT_INCLUDE_DIRS}) - -set(ADWAITA_THEME_PLUGIN_SRCS - adwaitathemeplugin.cpp - icon.cpp - theme.cpp -) - -add_library(adwaitathemeplugin SHARED ${ADWAITA_THEME_PLUGIN_SRCS}) - -target_link_libraries(adwaitathemeplugin - Qt6::Core - Qt6::Qml - Qt6::Quick - Qt6::QuickControls2 - Qt6::Widgets - ${ADWAITAQT_LIBRARIES} -) - -install(TARGETS adwaitathemeplugin DESTINATION ${QT6_INSTALL_QML}/org/fedoraproject/AdwaitaTheme) -install(FILES qmldir DESTINATION ${QT6_INSTALL_QML}/org/fedoraproject/AdwaitaTheme) -install(DIRECTORY qml/ DESTINATION ${QT6_INSTALL_QML}/QtQuick/Controls/org/fedoraproject/AdwaitaTheme) diff --git a/src/theme/adwaitathemeplugin.cpp b/src/theme/adwaitathemeplugin.cpp deleted file mode 100644 index 22a53988..00000000 --- a/src/theme/adwaitathemeplugin.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "adwaitathemeplugin.h" -#include "icon.h" -#include "theme.h" - -#include - -void AdwaitaThemePlugin::initializeEngine(QQmlEngine *engine, const char *uri) -{ - QQmlExtensionPlugin::initializeEngine(engine, uri); - - QQmlContext *context = engine->rootContext(); - - AdwaitaTheme *theme = new AdwaitaTheme(engine); - context->setContextProperty(QStringLiteral("theme"), theme); -} - -void AdwaitaThemePlugin::registerTypes(const char *uri) -{ - Q_ASSERT(uri == QByteArray("org.fedoraproject.AdwaitaTheme")); - - qmlRegisterUncreatableType(uri, 2, 0, "Theme", QStringLiteral("It is not possible to instantiate Theme directly.")); - qmlRegisterType(uri, 2, 0, "Icon"); -} diff --git a/src/theme/adwaitathemeplugin.h b/src/theme/adwaitathemeplugin.h deleted file mode 100644 index c086de83..00000000 --- a/src/theme/adwaitathemeplugin.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef ADWAITA_THEME_PLUGIN_H -#define ADWAITA_THEME_PLUGIN_H - -#include -#include - -class AdwaitaThemePlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) -public: - void initializeEngine(QQmlEngine *engine, const char *uri) override; - void registerTypes(const char *uri) override; -}; - -#endif // ADWAITA_THEME_PLUGIN_H diff --git a/src/theme/icon.cpp b/src/theme/icon.cpp deleted file mode 100644 index 2ffec695..00000000 --- a/src/theme/icon.cpp +++ /dev/null @@ -1,515 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2011 Marco Martin - * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez - * - * SPDX-License-Identifier: LGPL-2.0-or-later - */ - -#include "icon.h" -//#include "theme.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class ManagedTextureNode : public QSGSimpleTextureNode -{ - Q_DISABLE_COPY(ManagedTextureNode) -public: - ManagedTextureNode(); - - void setTexture(QSharedPointer texture); - -private: - QSharedPointer m_texture; -}; - -ManagedTextureNode::ManagedTextureNode() -{ -} - -void ManagedTextureNode::setTexture(QSharedPointer texture) -{ - m_texture = texture; - QSGSimpleTextureNode::setTexture(texture.data()); -} - -typedef QHash>> TexturesCache; - -struct ImageTexturesCachePrivate { - TexturesCache cache; -}; - -class ImageTexturesCache -{ -public: - ImageTexturesCache(); - ~ImageTexturesCache(); - - /** - * @returns the texture for a given @p window and @p image. - * - * If an @p image id is the same as one already provided before, we won't create - * a new texture and return a shared pointer to the existing texture. - */ - QSharedPointer loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options); - - QSharedPointer loadTexture(QQuickWindow *window, const QImage &image); - -private: - QScopedPointer d; -}; - -ImageTexturesCache::ImageTexturesCache() - : d(new ImageTexturesCachePrivate) -{ -} - -ImageTexturesCache::~ImageTexturesCache() -{ -} - -QSharedPointer ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options) -{ - qint64 id = image.cacheKey(); - QSharedPointer texture = d->cache.value(id).value(window).toStrongRef(); - - if (!texture) { - auto cleanAndDelete = [this, window, id](QSGTexture *texture) { - QHash> &textures = (d->cache)[id]; - textures.remove(window); - if (textures.isEmpty()) - d->cache.remove(id); - delete texture; - }; - texture = QSharedPointer(window->createTextureFromImage(image, options), cleanAndDelete); - (d->cache)[id][window] = texture.toWeakRef(); - } - - // if we have a cache in an atlas but our request cannot use an atlassed texture - // create a new texture and use that - // don't use removedFromAtlas() as that requires keeping a reference to the non atlased version - if (!(options & QQuickWindow::TextureCanUseAtlas) && texture->isAtlasTexture()) { - texture = QSharedPointer(window->createTextureFromImage(image, options)); - } - - return texture; -} - -QSharedPointer ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image) -{ - return loadTexture(window, image, {}); -} - -Q_GLOBAL_STATIC(ImageTexturesCache, s_iconImageCache) - -Icon::Icon(QQuickItem *parent) - : QQuickItem(parent) - , m_smooth(false) - , m_changed(false) - , m_active(false) - , m_selected(false) - , m_isMask(false) -{ - setFlag(ItemHasContents, true); -} - -Icon::~Icon() -{ -} - -void Icon::setSource(const QVariant &icon) -{ - if (m_source == icon) { - return; - } - m_source = icon; - m_monochromeHeuristics.clear(); - - // if (!m_theme) { - // m_theme = new AdwaitaTheme(this); - // Q_ASSERT(m_theme); - - // connect(m_theme, &AdwaitaTheme::colorsChanged, this, &QQuickItem::polish); - // } - - if (icon.typeId() == QMetaType::QString) { - const QString iconSource = icon.toString(); - m_isMaskHeuristic = (iconSource.endsWith(QLatin1String("-symbolic")) || iconSource.endsWith(QLatin1String("-symbolic-rtl")) || iconSource.endsWith(QLatin1String("-symbolic-ltr"))); - emit isMaskChanged(); - } - - m_loadedImage = QImage(); - - polish(); - emit sourceChanged(); - emit validChanged(); -} - -QVariant Icon::source() const -{ - return m_source; -} - -void Icon::setActive(const bool active) -{ - if (active == m_active) { - return; - } - m_active = active; - polish(); - emit activeChanged(); -} - -bool Icon::active() const -{ - return m_active; -} - -bool Icon::valid() const -{ - return !m_source.isNull(); -} - -void Icon::setSelected(const bool selected) -{ - if (selected == m_selected) { - return; - } - m_selected = selected; - polish(); - emit selectedChanged(); -} - -bool Icon::selected() const -{ - return m_selected; -} - -void Icon::setIsMask(bool mask) -{ - if (m_isMask == mask) { - return; - } - - m_isMask = mask; - m_isMaskHeuristic = mask; - polish(); - emit isMaskChanged(); -} - -bool Icon::isMask() const -{ - return m_isMask || m_isMaskHeuristic; -} - -void Icon::setColor(const QColor &color) -{ - if (m_color == color) { - return; - } - - m_color = color; - polish(); - emit colorChanged(); -} - -QColor Icon::color() const -{ - return m_color; -} - -int Icon::implicitWidth() const -{ - return 32; -} - -int Icon::implicitHeight() const -{ - return 32; -} - -void Icon::setSmooth(const bool smooth) -{ - if (smooth == m_smooth) { - return; - } - m_smooth = smooth; - polish(); - emit smoothChanged(); -} - -bool Icon::smooth() const -{ - return m_smooth; -} - -QSGNode *Icon::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData * /*data*/) -{ - if (m_source.isNull() || qFuzzyIsNull(width()) || qFuzzyIsNull(height())) { - delete node; - return Q_NULLPTR; - } - - if (m_changed || node == nullptr) { - const QSize itemSize(width(), height()); - QRect nodeRect(QPoint(0, 0), itemSize); - - ManagedTextureNode *mNode = dynamic_cast(node); - if (!mNode) { - delete node; - mNode = new ManagedTextureNode; - } - if (itemSize.width() != 0 && itemSize.height() != 0) { - mNode->setTexture(s_iconImageCache->loadTexture(window(), m_icon)); - if (m_icon.size() != itemSize) { - // At this point, the image will already be scaled, but we need to output it in - // the correct aspect ratio, painted centered in the viewport. So: - QRect destination(QPoint(0, 0), m_icon.size().scaled(itemSize, Qt::KeepAspectRatio)); - destination.moveCenter(nodeRect.center()); - nodeRect = destination; - } - } - mNode->setRect(nodeRect); - node = mNode; - if (m_smooth) { - mNode->setFiltering(QSGTexture::Linear); - } - m_changed = false; - } - - return node; -} - -void Icon::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - QQuickItem::geometryChange(newGeometry, oldGeometry); - if (newGeometry.size() != oldGeometry.size()) { - polish(); - } -} - -void Icon::updatePolish() -{ - QQuickItem::updatePolish(); - - if (m_source.isNull()) { - return; - } - - const QSize itemSize(width(), height()); - if (itemSize.width() != 0 && itemSize.height() != 0) { - switch (m_source.typeId()) { - case QMetaType::QPixmap: - m_icon = m_source.value().toImage(); - break; - case QMetaType::QImage: - m_icon = m_source.value(); - break; - case QMetaType::QBitmap: - m_icon = m_source.value().toImage(); - break; - case QMetaType::QIcon: - QScreen *screen; - m_icon = m_source.value().pixmap(itemSize, screen->devicePixelRatio()).toImage(); - break; - case QMetaType::QUrl: - case QMetaType::QString: - m_icon = findIcon(itemSize); - break; - case QMetaType::QBrush: - // todo: fill here too? - case QMetaType::QColor: - m_icon = QImage(itemSize, QImage::Format_Alpha8); - m_icon.fill(m_source.value()); - break; - default: - break; - } - - if (m_icon.isNull()) { - m_icon = QImage(itemSize, QImage::Format_Alpha8); - m_icon.fill(Qt::transparent); - } - - // const QColor tintColor = !m_color.isValid() || m_color == Qt::transparent ? (m_selected ? m_theme->highlightTextColor() : m_theme->textColor()) : m_color; - const QPalette &palette = QGuiApplication::palette(); - const QColor tintColor = !m_color.isValid() || m_color == Qt::transparent ? (m_selected ? palette.color(QPalette::HighlightedText) : palette.color(QPalette::Text)) : m_color; - - // TODO: initialize m_isMask with icon.isMask() - if (tintColor.alpha() > 0 && (isMask() || guessMonochrome(m_icon))) { - QPainter p(&m_icon); - p.setCompositionMode(QPainter::CompositionMode_SourceIn); - p.fillRect(m_icon.rect(), tintColor); - p.end(); - } - } - m_changed = true; - update(); -} - -QImage Icon::findIcon(const QSize &size) -{ - QImage img; - QString iconSource = m_source.toString(); - - if (iconSource.startsWith(QLatin1String("image://"))) { - QUrl iconUrl(iconSource); - QString iconProviderId = iconUrl.host(); - QString iconId = iconUrl.path(); - - // QRC paths are not correctly handled by .path() - if (iconId.size() >= 2 && iconId.startsWith(QLatin1String("/:"))) { - iconId.remove(0, 1); - } - - QSize actualSize; - QQuickImageProvider *imageProvider = dynamic_cast(qmlEngine(this)->imageProvider(iconProviderId)); - if (!imageProvider) - return img; - switch (imageProvider->imageType()) { - case QQmlImageProviderBase::Image: - img = imageProvider->requestImage(iconId, &actualSize, size); - break; - case QQmlImageProviderBase::Pixmap: - img = imageProvider->requestPixmap(iconId, &actualSize, size).toImage(); - break; - case QQmlImageProviderBase::Texture: - case QQmlImageProviderBase::Invalid: - case QQmlImageProviderBase::ImageResponse: - // will have to investigate this more - break; - } - } else { - if (iconSource.startsWith(QLatin1String("qrc:/"))) { - iconSource = iconSource.mid(3); - } else if (iconSource.startsWith(QLatin1String("file:/"))) { - iconSource = QUrl(iconSource).path(); - } - - QIcon icon; - const bool isPath = iconSource.contains(QLatin1String("/")); - if (isPath) { - icon = QIcon(iconSource); - } else { - if (icon.isNull()) { - icon = QIcon::fromTheme(iconSource); - } - } - if (!icon.isNull()) { - QScreen *screen; - img = icon.pixmap(size, screen->devicePixelRatio()).toImage(); - - /*const QColor tintColor = !m_color.isValid() || m_color == Qt::transparent ? (m_selected ? m_theme->highlightedTextColor() : m_theme->textColor()) : m_color; - - if (m_isMask || icon.isMask() || iconSource.endsWith(QLatin1String("-symbolic")) || iconSource.endsWith(QLatin1String("-symbolic-rtl")) || iconSource.endsWith(QLatin1String("-symbolic-ltr")) || guessMonochrome(img)) { - QPainter p(&img); - p.setCompositionMode(QPainter::CompositionMode_SourceIn); - p.fillRect(img.rect(), tintColor); - p.end(); - }*/ - } - } - - if (!iconSource.isEmpty() && img.isNull()) { - QScreen *screen; - img = QIcon::fromTheme(m_fallback).pixmap(size, screen->devicePixelRatio()).toImage(); - } - return img; -} - -QIcon::Mode Icon::iconMode() const -{ - if (!isEnabled()) { - return QIcon::Disabled; - } else if (m_selected) { - return QIcon::Selected; - } else if (m_active) { - return QIcon::Active; - } - return QIcon::Normal; -} - -bool Icon::guessMonochrome(const QImage &img) -{ - // don't try for too big images - if (img.width() >= 256) { - return false; - } - // round size to a standard size. hardcode as we can't use KIconLoader - int stdSize; - if (img.width() <= 16) { - stdSize = 16; - } else if (img.width() <= 22) { - stdSize = 22; - } else if (img.width() <= 24) { - stdSize = 24; - } else if (img.width() <= 32) { - stdSize = 32; - } else if (img.width() <= 48) { - stdSize = 48; - } else if (img.width() <= 64) { - stdSize = 64; - } else { - stdSize = 128; - } - - auto findIt = m_monochromeHeuristics.constFind(stdSize); - if (findIt != m_monochromeHeuristics.constEnd()) { - return findIt.value(); - } - - QHash dist; - int transparentPixels = 0; - int saturatedPixels = 0; - for (int x = 0; x < img.width(); x++) { - for (int y = 0; y < img.height(); y++) { - QColor color = QColor::fromRgba(qUnpremultiply(img.pixel(x, y))); - if (color.alpha() < 100) { - ++transparentPixels; - continue; - } else if (color.saturation() > 84) { - ++saturatedPixels; - } - dist[qGray(color.rgb())]++; - } - } - - QMultiMap reverseDist; - auto it = dist.constBegin(); - qreal entropy = 0; - while (it != dist.constEnd()) { - reverseDist.insert(it.value(), it.key()); - qreal probability = qreal(it.value()) / qreal(img.size().width() * img.size().height() - transparentPixels); - entropy -= probability * log(probability) / log(255); - ++it; - } - - // Arbitrarly low values of entropy and colored pixels - m_monochromeHeuristics[stdSize] = saturatedPixels <= (img.size().width() * img.size().height() - transparentPixels) * 0.3 && entropy <= 0.3; - return m_monochromeHeuristics[stdSize]; -} - -QString Icon::fallback() const -{ - return m_fallback; -} - -void Icon::setFallback(const QString &fallback) -{ - if (m_fallback != fallback) { - m_fallback = fallback; - Q_EMIT fallbackChanged(fallback); - } -} diff --git a/src/theme/icon.h b/src/theme/icon.h deleted file mode 100644 index a825810b..00000000 --- a/src/theme/icon.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2011 Marco Martin - * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez - * SPDX-FileCopyrightText: 2020 Carson Black - * - * SPDX-License-Identifier: LGPL-2.0-or-later - */ - -#pragma once - -#include -#include -#include -#include - -class AdwaitaTheme; - -/** - * Class for rendering an icon in UI. - */ -class Icon : public QQuickItem -{ - Q_OBJECT - - /** - * The source of this icon. An `Icon` can pull from: - * - * * The icon theme: - * @include icon/IconThemeSource.qml - * * The filesystem: - * @include icon/FilesystemSource.qml - * * Remote URIs: - * @include icon/InternetSource.qml - * * Custom providers: - * @include icon/CustomSource.qml - * * Your application's bundled resources: - * @include icon/ResourceSource.qml - * - * @note See https://doc.qt.io/qt-5/qtquickcontrols2-icons.html for how to - * bundle icon themes in your application to refer to them by name instead of - * by resource URL. - * - * @note Use `fallback` to provide a fallback theme name for icons. - */ - Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged) - - /** - * The name of a fallback icon to load from the icon theme when the `source` - * cannot be found. The default fallback icon is `"unknown"`. - * - * @include icon/Fallback.qml - * - * @note This will only be loaded if source is unavailable (e.g. it doesn't exist, or network issues have prevented loading). - */ - Q_PROPERTY(QString fallback READ fallback WRITE setFallback NOTIFY fallbackChanged) - - /** - * Whether pixmaps will be scaled smoothly if the size of this `Icon` is - * different from the source size. - */ - Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) - - /** - * The `implicitWidth` of this item, derived from the `source` image. - */ - Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT) - - /** - * The `implicitHeight` of this item, derived from the `source` image. - */ - Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT) - - /** - * Whether this icon will use the QIcon::Active mode when drawing the icon, - * resulting in a graphical effect being applied to the icon to indicate that - * it is currently active. - * - * This is typically used to indicate when an item is being hovered or pressed. - * - * @image html icon/active.png - * - * The color differences under the default KDE color palette, Breeze. Note - * that a dull highlight background is typically displayed behind active icons and - * it is recommended to add one if you are creating a custom component. - */ - Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) - - /** - * Whether this icon's `source` is valid and it is being used. - */ - Q_PROPERTY(bool valid READ valid NOTIFY validChanged) - - /** - * Whether this icon will use the QIcon::Selected mode when drawing the icon, - * resulting in a graphical effect being applied to the icon to indicate that - * it is currently selected. - * - * This is typically used to indicate when a list item is currently selected. - * - * @image html icon/selected.png - * - * The color differences under the default KDE color palette, Breeze. Note - * that a blue background is typically displayed behind selected elements. - */ - Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged) - - /** - * Whether this icon will be treated as a mask. When an icon is being used - * as a mask, all non-transparent colors are replaced with the color provided in the Icon's - * @link Icon::color color @endlink property. - * - * @see color - */ - Q_PROPERTY(bool isMask READ isMask WRITE setIsMask NOTIFY isMaskChanged) - - /** - * The color to use when drawing this icon when `isMask` is enabled. - * If this property is not set or is `Qt::transparent`, the icon will use - * the text or the selected text color, depending on if `selected` is set to - * true. - */ - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - -public: - Icon(QQuickItem *parent = nullptr); - ~Icon(); - - void setSource(const QVariant &source); - QVariant source() const; - - int implicitWidth() const; - int implicitHeight() const; - - void setSmooth(const bool smooth); - bool smooth() const; - - void setActive(bool active = true); - bool active() const; - - bool valid() const; - - void setSelected(bool selected = true); - bool selected() const; - - void setIsMask(bool mask); - bool isMask() const; - - void setColor(const QColor &color); - QColor color() const; - - QString fallback() const; - void setFallback(const QString &fallback); - - QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override; - -Q_SIGNALS: - void sourceChanged(); - void smoothChanged(); - void enabledChanged(); - void activeChanged(); - void validChanged(); - void selectedChanged(); - void isMaskChanged(); - void colorChanged(); - void fallbackChanged(const QString &fallback); - -protected: - void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; - QImage findIcon(const QSize &size); - QIcon::Mode iconMode() const; - bool guessMonochrome(const QImage &img); - void updatePolish() override; - -private: - AdwaitaTheme *m_theme = nullptr; - QHash m_monochromeHeuristics; - QVariant m_source; - bool m_smooth; - bool m_changed; - bool m_active; - bool m_selected; - bool m_isMask; - bool m_isMaskHeuristic = false; - QImage m_loadedImage; - QColor m_color = Qt::transparent; - QString m_fallback = QStringLiteral("unknown"); - - QImage m_icon; -}; diff --git a/src/theme/qml/Button.qml b/src/theme/qml/Button.qml deleted file mode 100644 index 9650df59..00000000 --- a/src/theme/qml/Button.qml +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Templates as T -import QtQuick.Layouts -import org.fedoraproject.AdwaitaTheme -import "private" as Private - -T.Button { - id: control - - property bool destructiveAction: false - - implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding - implicitHeight: contentItem.implicitHeight + bottomPadding + topPadding - - leftPadding: theme.buttonMarginWidth - rightPadding: theme.buttonMarginWidth - bottomPadding: theme.buttonMarginWidth - topPadding: theme.buttonMarginWidth - - Layout.minimumWidth: control.text ? theme.buttonMinimumWidth : theme.buttonMinimumWidth / 2 - - hoverEnabled: true - - contentItem: RowLayout { - Icon { - id: icon - - Layout.alignment: Qt.AlignCenter - - Layout.fillWidth: true - Layout.fillHeight: true - - Layout.minimumWidth: Math.min(parent.width, parent.height, implicitWidth) - Layout.minimumHeight: Math.min(parent.width, parent.height, implicitHeight) - - Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : Number.POSITIVE_INFINITY - Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : Number.POSITIVE_INFINITY - - visible: source.length > 0 && control.display !== T.Button.TextOnly - source: control.icon ? (control.icon.name || control.icon.source) : "" - } - - Label { - id: label - Layout.leftMargin: theme.buttonItemSpacing - Layout.rightMargin: theme.buttonItemSpacing - Layout.fillWidth: true - text: control.text - font: control.font - color: control.enabled ? control.highlighted ? theme.highlightTextColor : theme.textColor : theme.disabledTextColor - horizontalAlignment: icon.visible ? Text.AlignLeft : Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - visible: control.text - } - } - - background: Private.ButtonFrame { - anchors.fill: parent - flat: control.flat - highlighted: control.highlighted - destructiveAction: control.destructiveAction - } -} - diff --git a/src/theme/qml/CheckBox.qml b/src/theme/qml/CheckBox.qml deleted file mode 100644 index 2397e230..00000000 --- a/src/theme/qml/CheckBox.qml +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme - -T.CheckBox { - id: control - - // FIXME: windows seems to need more space for some reason - implicitWidth: implicitContentWidth + leftPadding + rightPadding + (Qt.platform.os == "windows" ? indicator.width : spacing) - implicitHeight: implicitContentHeight + bottomPadding + topPadding - - padding: theme.checkboxItemSpacing - spacing: theme.checkboxItemSpacing - hoverEnabled: true - - indicator: CheckIndicator { - x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 - y: control.topPadding + (control.availableHeight - height) / 2 - control: control - } - - contentItem: Text { - id: label - leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0 - rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0 - text: control.text - font: control.font - color: control.enabled ? theme.textColor : theme.disabledTextColor - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - visible: control.text - } -} diff --git a/src/theme/qml/CheckIndicator.qml b/src/theme/qml/CheckIndicator.qml deleted file mode 100644 index 8a2b4b93..00000000 --- a/src/theme/qml/CheckIndicator.qml +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import org.fedoraproject.AdwaitaTheme - -Rectangle { - id: root - - property Item control - - width: theme.checkboxSize - 4 - height: theme.checkboxSize - 4 - - radius: Math.max(theme.frameRadius - 1, 0) - - readonly property int animationDuration: 150 - - gradient: Gradient { - GradientStop { - position: 0.0 - color: root.topColor - } - GradientStop { - position: 1.0 - color: root.bottomColor - } - } - - property color bottomColor: { - return theme.getCheckBoxBottomColor(control.hovered, control.down, control.checked || ((typeof control.checkState !== "undefined") && control.checkState == Qt.Checked)) - } - - property color topColor: { - return theme.getCheckBoxTopColor(control.hovered, control.down, control.checked || ((typeof control.checkState !== "undefined") && control.checkState == Qt.Checked)) - } - - border { - color: theme.getCheckBoxOutlineColor(control.hovered, control.down, control.checked || ((typeof control.checkState !== "undefined") && control.checkState == Qt.Checked)) - } - - Item { - visible: (typeof control.checkState !== "undefined") && control.checkState == Qt.Checked - opacity: visible - rotation: -45 - anchors.fill: parent - Rectangle { - color: theme.highlightTextColor - x: 5 - y: 4 - width: 3 - height: 6 - radius: 4 - } - Rectangle { - color: theme.highlightTextColor - x: 5 - y: 8 - width: 10 - height: 3 - radius: 7 - } - - Behavior on opacity { PropertyAnimation { duration: root.animationDuration } } - } -} diff --git a/src/theme/qml/ComboBox.qml b/src/theme/qml/ComboBox.qml deleted file mode 100644 index 6098de95..00000000 --- a/src/theme/qml/ComboBox.qml +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Shapes -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme -import "private" as Private - -T.ComboBox { - id: control - - implicitWidth: Math.max(background ? background.implicitWidth : 0, - contentItem.implicitWidth + leftPadding + rightPadding) + spacing + indicator.implicitWidth + rightPadding - implicitHeight: Math.max(background ? background.implicitHeight : 0, - contentItem.implicitHeight + bottomPadding + topPadding) - - spacing: theme.menuItemSpacing - leftPadding: theme.comboBoxMarginWidth - rightPadding: theme.comboBoxMarginWidth - bottomPadding: theme.comboBoxMarginHeight - topPadding: theme.comboBoxMarginHeight - - hoverEnabled: true - - delegate: MenuItem { - width: parent.width - theme.frameWidth - text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData - font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal - highlighted: control.highlightedIndex == index - hoverEnabled: control.hoverEnabled - x: theme.frameWidth / 2 - } - - indicator: Shape { - implicitHeight: 10 - implicitWidth: 10 - x: control.mirrored ? control.leftPadding - 2 : control.width - width - control.rightPadding + 2 - y: control.topPadding + control.availableHeight / 2 - - ShapePath { - fillColor: theme.textColor - strokeColor: theme.textColor - capStyle: ShapePath.FlatCap - joinStyle: ShapePath.MiterJoin - - startX: -4 - startY: -2 - PathLine { x: 0; y: 2 } - PathLine { x: 4; y: -2 } - } - } - - contentItem: T.TextField { - anchors { - fill: parent - leftMargin: control.leftPadding - rightMargin: control.rightPadding + indicator.width + control.spacing - bottomMargin: control.bottomPadding - topMargin: control.topPadding - } - implicitWidth: contentWidth - text: control.editable ? control.editText : control.displayText - - enabled: control.editable - autoScroll: control.editable - readOnly: control.down - inputMethodHints: control.inputMethodHints - validator: control.validator - - font: control.font - color: control.enabled ? theme.textColor : theme.disabledTextColor - selectionColor: theme.highlightColor - selectedTextColor: theme.highlightTextColor - verticalAlignment: Text.AlignVCenter - } - - background: Rectangle { - id: rect - anchors.fill: parent - implicitHeight: theme.comboBoxMinimumHeight - implicitWidth: theme.comboBoxMinimumWidth - radius: theme.frameRadius - visible: control.flat ? control.pressed || control.checked : true - - readonly property int animationDuration: 150 - - gradient: Gradient { - GradientStop { - position: 0.0 - color: control.editable ? control.enabled ? theme.baseColor : theme.windowColor : rect.topColor - Behavior on color { ColorAnimation { duration: rect.animationDuration } } - } - GradientStop { - position: 1.0 - color: control.editable ? control.enabled ? theme.baseColor :theme.windowColor : rect.bottomColor - Behavior on color { ColorAnimation { duration: rect.animationDuration } } - } - } - - property color bottomColor: { - return theme.getButtonBottomColor(false, false, control.hovered, control.pressed || control.checked) - } - - property color topColor: { - return theme.getButtonTopColor(false, false, control.hovered, control.pressed || control.checked) - } - - border { - color: control.editable ? control.focus ? theme.highlightColor : theme.getButtonOutlineColor(false, false, control.hovered, false) : - theme.getButtonOutlineColor(false, false, control.hovered, control.pressed || control.checked) - } - } - - popup: T.Popup { - x: control.mirrored ? control.width - width : 0 - y: control.height - width: control.width - height: contentItem.implicitHeight + (theme.menuItemSpacing * 2) - topMargin: 6 - bottomMargin: 6 - - contentItem: ListView { - id: listView - clip: true - implicitHeight: contentHeight - model: control.popup.visible ? control.delegateModel : null - currentIndex: control.highlightedIndex - highlightRangeMode: ListView.ApplyRange - highlightMoveDuration: 0 - topMargin: theme.menuItemSpacing - T.ScrollBar.vertical: ScrollBar { } - } - - background: Rectangle { - anchors { - fill: parent - margins: 1 - } - color: theme.baseColor - border.color: theme.getButtonOutlineColor(false, false, false, false) - radius: theme.frameRadius - } - } -} diff --git a/src/theme/qml/Label.qml b/src/theme/qml/Label.qml deleted file mode 100644 index 974bcad2..00000000 --- a/src/theme/qml/Label.qml +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme -import "private" as Private - - -T.Label { - id: control - - verticalAlignment: Text.AlignVCenter - - color: theme.textColor - linkColor: theme.linkColor - - Accessible.role: Accessible.StaticText - Accessible.name: text -} - - diff --git a/src/theme/qml/MenuItem.qml b/src/theme/qml/MenuItem.qml deleted file mode 100644 index 267c0d42..00000000 --- a/src/theme/qml/MenuItem.qml +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Shapes -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme -import "private" as Private - -T.MenuItem { - id: control - - implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - contentItem.implicitWidth + leftPadding + rightPadding + spacing + (arrow ? arrow.implicitWidth : 0)) - implicitHeight: Math.max(background ? background.implicitHeight : 0, - contentItem.implicitHeight+ topPadding + bottomPadding, - indicator ? indicator.implicitHeight : 0) - - bottomPadding: theme.menuItemMarginWidth - topPadding: theme.menuItemMarginWidth - leftPadding: theme.menuItemMarginWidth - rightPadding: theme.menuItemMarginWidth - - spacing: theme.menuItemSpacing - - icon.width: 16 - icon.height: 16 - - contentItem: RowLayout { - Icon { - id: icon - - Layout.alignment: Qt.AlignCenter - - Layout.fillWidth: true - Layout.fillHeight: true - - Layout.minimumWidth: Math.min(parent.width, parent.height, implicitWidth) - Layout.minimumHeight: Math.min(parent.width, parent.height, implicitHeight) - - Layout.maximumWidth: control.icon.width > 0 ? control.icon.width : Number.POSITIVE_INFINITY - Layout.maximumHeight: control.icon.height > 0 ? control.icon.height : Number.POSITIVE_INFINITY - - visible: source.length > 0 - source: control.icon ? (control.icon.name || control.icon.source) : "" - } - - Label { - id: label - Layout.leftMargin: control.leftPadding - Layout.fillWidth: true - text: control.text - font: control.font - color: control.highlighted ? theme.highlightTextColor : control.enabled ? theme.textColor : theme.disabledTextColor - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - visible: control.text - } - } - - arrow: Shape { - implicitHeight: 10 - implicitWidth: 10 - x: control.mirrored ? control.leftPadding : control.width - width - control.rightPadding - y: control.topPadding + control.availableHeight / 2 - visible: control.subMenu - - ShapePath { - fillColor: theme.textColor - strokeColor: theme.textColor - capStyle: ShapePath.FlatCap - joinStyle: ShapePath.MiterJoin - - startX: -2 - startY: -4 - PathLine { x: 2; y: 0 } - PathLine { x: -2; y: 4 } - } - } - - indicator: CheckIndicator { - x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 - y: control.topPadding + (control.availableHeight - height) / 2 - control: control - visible: control.checkable - } - - background: Rectangle { - implicitWidth: 200 - implicitHeight: 20 - - color: theme.highlightColor - visible: control.down || control.highlighted - } -} diff --git a/src/theme/qml/ProgressBar.qml b/src/theme/qml/ProgressBar.qml deleted file mode 100644 index d5b05a8a..00000000 --- a/src/theme/qml/ProgressBar.qml +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme - -T.ProgressBar { - id: control - - implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, - implicitContentWidth + leftPadding + rightPadding) - implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - implicitContentHeight + topPadding + bottomPadding) - - property color progressBarColor: theme.highlightColor - - contentItem: Item { - scale: control.mirrored ? -1 : 1 - - Rectangle { - id: indicator - height: parent.height - width: control.indeterminate ? theme.progressBarBusyIndicatorSize : parent.width * control.position - color: control.progressBarColor - border.color: theme.getProgressBarOutlineColor() - } - - SequentialAnimation { - id: animation - loops: Animation.Infinite - - alwaysRunToEnd: true - running: control.indeterminate && control.visible - - PropertyAnimation { - target: indicator - property: "x" - duration: 2500 - from: 1 - to: control.width - indicator.width - } - PropertyAnimation { - target: indicator - property: "x" - duration: 2500 - to: 1 - } - } - } - - background: Rectangle { - implicitWidth: 100 - implicitHeight: theme.progressBarThickness + 0.5 - color: theme.getProgressBarColor() - border.color: theme.getProgressBarOutlineColor() - radius: 0.5 - } - -} diff --git a/src/theme/qml/RadioButton.qml b/src/theme/qml/RadioButton.qml deleted file mode 100644 index bda878a1..00000000 --- a/src/theme/qml/RadioButton.qml +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme - -T.RadioButton { - id: control - - // FIXME: windows seems to need more space for some reason - implicitWidth: implicitContentWidth + leftPadding + rightPadding + (Qt.platform.os == "windows" ? indicator.width : spacing) - implicitHeight: implicitContentHeight + bottomPadding + topPadding - - padding: theme.checkboxItemSpacing - spacing: theme.checkboxItemSpacing - hoverEnabled: true - - indicator: RadioIndicator { - x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 - y: control.topPadding + (control.availableHeight - height) / 2 - control: control - } - - contentItem: Text { - id: label - leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0 - rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0 - text: control.text - font: control.font - color: control.enabled ? theme.textColor : theme.disabledTextColor - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight - visible: control.text - } -} diff --git a/src/theme/qml/RadioIndicator.qml b/src/theme/qml/RadioIndicator.qml deleted file mode 100644 index dd2190d8..00000000 --- a/src/theme/qml/RadioIndicator.qml +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import org.fedoraproject.AdwaitaTheme - -Rectangle { - id: root - - property Item control - - width: theme.checkboxSize - 4 - height: theme.checkboxSize - 4 - - radius: width / 2 - - readonly property int animationDuration: 150 - - gradient: Gradient { - GradientStop { - position: 0.0 - color: root.topColor - } - GradientStop { - position: 1.0 - color: root.bottomColor - } - } - - property color bottomColor: { - return theme.getCheckBoxBottomColor(control.hovered, control.down, control.checked || ((typeof control.checkState !== "undefined") && control.checkState == Qt.Checked)) - } - - property color topColor: { - return theme.getCheckBoxTopColor(control.hovered, control.down, control.checked || ((typeof control.checkState !== "undefined") && control.checkState == Qt.Checked)) - } - - border { - color: theme.getCheckBoxOutlineColor(control.hovered, control.down, control.checked || ((typeof control.checkState !== "undefined") && control.checkState == Qt.Checked)) - } - - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - visible: control.checked - opacity: visible - color: theme.highlightTextColor - width: parent.width / 2 - height: parent.width / 2 - radius: width / 2 - - Behavior on opacity { PropertyAnimation { duration: root.animationDuration } } - } -} diff --git a/src/theme/qml/ScrollBar.qml b/src/theme/qml/ScrollBar.qml deleted file mode 100644 index c308c308..00000000 --- a/src/theme/qml/ScrollBar.qml +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme -import "private" as Private - -T.ScrollBar { - id: control - - implicitWidth: implicitContentWidth + leftPadding + rightPadding - implicitHeight: implicitContentHeight + topPadding + bottomPadding - - leftPadding: 4 - rightPadding: 4 - bottomPadding: 4 - topPadding: 4 - // FIXME - // Workaround for me not being able to hide horizontal scrollbar - visible: control.size < 1.0 && orientation !== Qt.Horizontal - minimumSize: orientation == Qt.Horizontal ? height / width : width / height - hoverEnabled: true - - contentItem: Rectangle { - implicitWidth: control.pressed || control.hovered ? 6 : 2 - implicitHeight: control.pressed || control.hovered ? 6 : 2 - radius: width / 2 - color: theme.getScrollBarHandleColor(control.hovered, control.pressed) - } - - background: Item { - visible: control.size < 1.0 && (control.pressed || control.hovered) - implicitWidth: implicitWidth - implicitHeight: implicitWidth - Rectangle { - anchors { - top: parent.top - bottom: parent.bottom - left: parent.left - } - width: parent.width - color: theme.getScrollBarGrooveColor() - border.color: Qt.darker(palette.window, 1.2) // FIXME - border.width: 1 - } - } -} diff --git a/src/theme/qml/TextField.qml b/src/theme/qml/TextField.qml deleted file mode 100644 index bf75b2c0..00000000 --- a/src/theme/qml/TextField.qml +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import QtQuick.Controls -import QtQuick.Controls.impl -import QtQuick.Layouts -import QtQuick.Templates as T -import org.fedoraproject.AdwaitaTheme -import "private" as Private - -T.TextField { - id: control - - implicitWidth: implicitBackgroundWidth + leftInset + rightInset - || Math.max(contentWidth, placeholder.implicitWidth) + leftPadding + rightPadding - implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, - contentHeight + topPadding + bottomPadding, - placeholder.implicitHeight + topPadding + bottomPadding) - - leftPadding: theme.lineEditMarginWidth - rightPadding: theme.lineEditMarginWidth - bottomPadding: theme.lineEditMarginHeight - topPadding: theme.lineEditMarginHeight - - color: theme.textColor - selectionColor: theme.highlightColor - selectedTextColor: theme.highlightTextColor - placeholderTextColor: Qt.hsla(control.color.hslHue, control.color.hslSaturation, control.color.hslLightness, 0.6) - verticalAlignment: TextInput.AlignVCenter - - Label { - id: placeholder - x: control.leftPadding - y: control.topPadding - width: control.width - (control.leftPadding + control.rightPadding) - height: control.height - (control.topPadding + control.bottomPadding) - - text: control.placeholderText - font: control.font - color: control.placeholderTextColor - verticalAlignment: control.verticalAlignment - visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter) - elide: Text.ElideRight - renderType: control.renderType - } - - background: Item { - implicitWidth: theme.lineEditMinimumWidth - implicitHeight: theme.lineEditMinimumHeight - - Rectangle { - anchors.fill: parent - anchors.margins: 1 - border.color: control.focus ? theme.highlightColor : theme.getButtonOutlineColor(false, false, control.hovered, false) - color: control.enabled ? theme.baseColor :theme.windowColor - radius: theme.frameRadius - } - } -} diff --git a/src/theme/qml/private/ButtonFrame.qml b/src/theme/qml/private/ButtonFrame.qml deleted file mode 100644 index b055acef..00000000 --- a/src/theme/qml/private/ButtonFrame.qml +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2016 Martin Bříza - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import QtQuick -import org.fedoraproject.AdwaitaTheme - -Item { - id: root - - // TODO add a focus rect - - property bool flat: false - property bool highlighted: false - property bool destructiveAction: false - - Rectangle { - id: rect - anchors.fill: parent - radius: theme.frameRadius - visible: flat ? control.pressed || control.checked : true - - readonly property int animationDuration: 150 - - gradient: Gradient { - GradientStop { - position: 0.0 - color: rect.topColor - Behavior on color { ColorAnimation { duration: rect.animationDuration } } - } - GradientStop { - position: 1.0 - color: rect.bottomColor - Behavior on color { ColorAnimation { duration: rect.animationDuration } } - } - } - - property color bottomColor: { - return theme.getButtonBottomColor(root.highlighted, root.destructiveAction, control.hovered, control.pressed || control.checked) - } - - property color topColor: { - return theme.getButtonTopColor(root.highlighted, root.destructiveAction, control.hovered, control.pressed || control.checked) - } - - border { - color: theme.getButtonOutlineColor(root.highlighted, root.destructiveAction, control.hovered, control.pressed || control.checked) - } - } -} diff --git a/src/theme/qml/qmldir b/src/theme/qml/qmldir deleted file mode 100644 index 6310a061..00000000 --- a/src/theme/qml/qmldir +++ /dev/null @@ -1,27 +0,0 @@ -module org.fedoraproject.AdwaitaTheme -Button 2.0 Button.qml -Button 6.0 Button.qml -CheckBox 2.0 CheckBox.qml -CheckBox 6.0 CheckBox.qml -CheckIndicator 2.0 CheckIndicator.qml -CheckIndicator 6.0 CheckIndicator.qml -ComboBox 2.0 ComboBox.qml -ComboBox 6.0 ComboBox.qml -Label 2.0 Label.qml -Label 6.0 Label.qml -MenuItem 2.0 MenuItem.qml -MenuItem 6.0 MenuItem.qml -ProgressBar 2.0 ProgressBar.qml -ProgressBar 6.0 ProgressBar.qml -RadioButton 2.0 RadioButton.qml -RadioButton 6.0 RadioButton.qml -RadioIndicator 2.0 RadioIndicator.qml -RadioIndicator 6.0 RadioIndicator.qml -ScrollBar 2.0 ScrollBar.qml -ScrollBar 6.0 ScrollBar.qml -TextField 2.0 TextField.qml -TextField 6.0 TextField.qml - - - - diff --git a/src/theme/qmldir b/src/theme/qmldir deleted file mode 100644 index f223dbf8..00000000 --- a/src/theme/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -module org.fedoraproject.AdwaitaTheme -plugin adwaitathemeplugin diff --git a/src/theme/theme.cpp b/src/theme/theme.cpp deleted file mode 100644 index 3d3a9512..00000000 --- a/src/theme/theme.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "theme.h" - -#include -#include - -AdwaitaTheme::AdwaitaTheme(QObject *parent) - : QObject(parent) - , m_darkMode(false) -{ - // Just guess dark mode for now based on text color - const QColor textColor = QGuiApplication::palette().color(QPalette::Text); - if (qSqrt(((textColor.red() * textColor.red()) * 0.299) + ((textColor.green() * textColor.green()) * 0.587) + ((textColor.blue() * textColor.blue()) * 0.114)) > 128) { - m_darkMode = true; - } - - m_palette = Adwaita::Colors::palette(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); -} - -AdwaitaTheme *AdwaitaTheme::qmlAttachedProperties(QObject *object) -{ - return new AdwaitaTheme(object); -} - -QColor AdwaitaTheme::buttonOutlineColor() const -{ - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - return Adwaita::Colors::buttonOutlineColor(Adwaita::StyleOptions(m_palette)); -} - -QColor AdwaitaTheme::getButtonBottomColor(bool highlighted, bool destructiveAction, bool hovered, bool pressed) -{ - // Give destructive action higher priority and leave "highlighted" as fallback - if (destructiveAction) { - if (pressed) { - return m_darkMode ? QColor("#8a1116") : QColor("#a0131a"); - } else if (hovered) { - // FIXME: this is not 1:1 from Adwaita, but we need to make it - // lighter to highlight the hover - return m_darkMode ? Adwaita::Colors::lighten(QColor("#ae151c"), 0.01) : QColor("#e01b24"); - } else { - return m_darkMode ? QColor("#ae151c") : QColor("#ce1921"); - } - } - - if (highlighted) { - if (pressed) { - return m_darkMode ? QColor("#103e75") : QColor("#1961b9"); - } else if (hovered) { - return m_darkMode ? QColor("#155099") : QColor("#3584e4"); - } else { - return m_darkMode ? QColor("#155099") : QColor("#2379e2"); - } - } - - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setMouseOver(hovered); - styleOptions.setSunken(pressed); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - - const QColor color = Adwaita::Colors::buttonBackgroundColor(styleOptions); - - // FIXME - return hovered && m_darkMode ? Adwaita::Colors::lighten(color, 0.01) : color; -} - -QColor AdwaitaTheme::getButtonTopColor(bool highlighted, bool destructiveAction, bool hovered, bool pressed) -{ - if (destructiveAction) { - if (pressed) { - return m_darkMode ? QColor("#8a1116") : QColor("#a0131a"); - } else if (hovered) { - // FIXME: this is not 1:1 from Adwaita, but we need to make it - // lighter to highlight the hover - return m_darkMode ? Adwaita::Colors::lighten(QColor("#b2161d"), 0.01) : QColor("#e41c26"); - } else { - return m_darkMode ? QColor("#b2161d") : QColor("#e01b24"); - } - } - - if (highlighted) { - if (pressed) { - return m_darkMode ? QColor("#103e75") : QColor("#1961b9"); - } else if (hovered) { - return m_darkMode ? QColor("#1655a2") : QColor("#3987e5"); - } else { - return m_darkMode ? QColor("#15539e") : QColor("#3483e4"); - } - } - - const QColor color = getButtonBottomColor(highlighted, destructiveAction, hovered, pressed); - - // TODO: separate this from Adwaita::Helper::renderButtonFrame() - if (pressed) { - // Pressed button in normal and dark mode is not a gradient, but just an image consting from same $color - return color; - } else if (hovered) { - return m_darkMode ? Adwaita::Colors::lighten(color, 0.02) : Adwaita::Colors::lighten(color, 0.01); - } else { - return m_darkMode ? Adwaita::Colors::lighten(color, 0.01) : Adwaita::Colors::lighten(color, 0.04); - } -} - -QColor AdwaitaTheme::getButtonOutlineColor(bool highlighted, bool destructiveAction, bool hovered, bool pressed) -{ - if (destructiveAction) { - return m_darkMode ? QColor("#851015") : QColor("#b2161d"); - } - - if (highlighted) { - return m_darkMode ? QColor("#0f3b71") : QColor("#1b6acb"); - } - - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setMouseOver(hovered); - styleOptions.setSunken(pressed); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - - return Adwaita::Colors::buttonOutlineColor(styleOptions); -} - -QColor AdwaitaTheme::getCheckBoxBottomColor(bool hovered, bool pressed, bool checked) -{ - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setMouseOver(hovered); - styleOptions.setSunken(pressed); - styleOptions.setCheckboxState(checked ? Adwaita::CheckBoxState::CheckOn : Adwaita::CheckBoxState::CheckOff); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - - const QColor color = Adwaita::Colors::indicatorBackgroundColor(styleOptions); - - // TODO: separate this from Adwaita::Helper::renderCheckBoxFrame() - if (!checked) { - if (pressed) { - // Pressed button in normal and dark mode is not a gradient, but just an image consting from same $color - return color; - } else if (hovered) { - QColor baseColor = m_darkMode ? color : Adwaita::Colors::darken(color, 0.09); - return m_darkMode ? Adwaita::Colors::darken(baseColor, 0.04) : color; - } else { - QColor baseColor = m_darkMode ? Adwaita::Colors::lighten(color, 0.03) : Adwaita::Colors::darken(color, 0.05); - return m_darkMode ? Adwaita::Colors::darken(baseColor, 0.06) : baseColor; - } - } else { - return Adwaita::Colors::lighten(color, 0.04); - } -} - -QColor AdwaitaTheme::getCheckBoxTopColor(bool hovered, bool pressed, bool checked) -{ - const QColor color = getCheckBoxBottomColor(hovered, pressed, checked); - - // TODO: separate this from Adwaita::Helper::renderCheckBoxFrame() - if (!checked) { - if (pressed) { - // Pressed button in normal and dark mode is not a gradient, but just an image consting from same $color - return color; - } else if (hovered) { - QColor baseColor = m_darkMode ? color : Adwaita::Colors::darken(color, 0.09); - return m_darkMode ? color : Adwaita::Colors::lighten(baseColor, 0.04); - } else { - return m_darkMode ? color : color; - } - } else { - return Adwaita::Colors::lighten(color, 0.04); - } -} - -QColor AdwaitaTheme::getCheckBoxOutlineColor(bool hovered, bool pressed, bool checked) -{ - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setMouseOver(hovered); - styleOptions.setSunken(pressed); - styleOptions.setCheckboxState(checked ? Adwaita::CheckBoxState::CheckOn : Adwaita::CheckBoxState::CheckOff); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - - return Adwaita::Colors::indicatorOutlineColor(styleOptions); -} - -QColor AdwaitaTheme::getProgressBarColor() -{ - return m_palette.currentColorGroup() ? m_palette.color(QPalette::Window) : Adwaita::Colors::mix(getProgressBarOutlineColor(), m_palette.color(QPalette::Window)); -} - -QColor AdwaitaTheme::getProgressBarOutlineColor() -{ - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - - return Adwaita::Colors::buttonOutlineColor(styleOptions); -} - -QColor AdwaitaTheme::getScrollBarGrooveColor() -{ - if (m_darkMode) { - return Adwaita::Colors::mix(windowColor(), baseColor(), 0.5); - } else { - return Adwaita::Colors::mix(windowColor(), baseColor(), 0.2); - } -} - -QColor AdwaitaTheme::getScrollBarHandleColor(bool hovered, bool pressed) -{ - Adwaita::StyleOptions styleOptions(m_palette); - styleOptions.setMouseOver(hovered); - styleOptions.setSunken(pressed); - styleOptions.setColorVariant(m_darkMode ? Adwaita::ColorVariant::AdwaitaDark : Adwaita::ColorVariant::Adwaita); - - return Adwaita::Colors::scrollBarHandleColor(styleOptions); -} diff --git a/src/theme/theme.h b/src/theme/theme.h deleted file mode 100644 index fde32751..00000000 --- a/src/theme/theme.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Fedora Media Writer - * Copyright (C) 2020 Jan Grulich - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef ADWAITA_THEME_H -#define ADWAITA_THEME_H - -#include -#include -#include -#include - -#include -#include - -class AdwaitaTheme : public QObject -{ - Q_OBJECT - // Button - Q_PROPERTY(int buttonMarginHeight READ buttonMarginHeight CONSTANT) - Q_PROPERTY(int buttonMarginWidth READ buttonMarginWidth CONSTANT) - Q_PROPERTY(int buttonMinimumHeight READ buttonMinimumHeight CONSTANT) - Q_PROPERTY(int buttonMinimumWidth READ buttonMinimumWidth CONSTANT) - Q_PROPERTY(int buttonItemSpacing READ buttonItemSpacing CONSTANT) - - // Checkbox - Q_PROPERTY(int checkboxItemSpacing READ checkboxItemSpacing CONSTANT) - Q_PROPERTY(int checkboxFocusMarginWidth READ checkboxFocusMarginWidth CONSTANT) - Q_PROPERTY(int checkboxSize READ checkboxSize CONSTANT) - - // ComboBox - Q_PROPERTY(int comboBoxMarginHeight READ comboBoxMarginHeight CONSTANT) - Q_PROPERTY(int comboBoxMarginWidth READ comboBoxMarginWidth CONSTANT) - Q_PROPERTY(int comboBoxMinimumHeight READ comboBoxMinimumHeight CONSTANT) - Q_PROPERTY(int comboBoxMinimumWidth READ comboBoxMinimumWidth CONSTANT) - - // Frame - Q_PROPERTY(int frameRadius READ frameRadius CONSTANT) - Q_PROPERTY(int frameWidth READ frameWidth CONSTANT) - - // LineEdit - Q_PROPERTY(int lineEditFrameWidth READ lineEditFrameWidth CONSTANT) - Q_PROPERTY(int lineEditMarginHeight READ lineEditMarginHeight CONSTANT) - Q_PROPERTY(int lineEditMarginWidth READ lineEditMarginWidth CONSTANT) - Q_PROPERTY(int lineEditMinimumHeight READ lineEditMinimumHeight CONSTANT) - Q_PROPERTY(int lineEditMinimumWidth READ lineEditMinimumWidth CONSTANT) - - // MenuItem - Q_PROPERTY(int menuItemSpacing READ menuItemSpacing CONSTANT) - Q_PROPERTY(int menuItemMarginWidth READ menuItemMarginWidth CONSTANT) - - // Progressbar - Q_PROPERTY(int progressBarBusyIndicatorSize READ progressBarBusyIndicatorSize CONSTANT) - Q_PROPERTY(int progressBarThickness READ progressBarThickness CONSTANT) - - // Colors - Q_PROPERTY(QColor baseColor READ baseColor CONSTANT) - Q_PROPERTY(QColor buttonColor READ buttonColor CONSTANT) - Q_PROPERTY(QColor buttonOutlineColor READ buttonOutlineColor CONSTANT) - Q_PROPERTY(QColor disabledTextColor READ disabledTextColor CONSTANT) - Q_PROPERTY(QColor highlightColor READ highlightColor CONSTANT) - Q_PROPERTY(QColor highlightTextColor READ highlightTextColor CONSTANT) - Q_PROPERTY(QColor linkColor READ linkColor CONSTANT) - Q_PROPERTY(QColor textColor READ textColor CONSTANT) - Q_PROPERTY(QColor windowColor READ windowColor CONSTANT) - - Q_PROPERTY(QColor darkMode READ darkMode CONSTANT) -public: - explicit AdwaitaTheme(QObject *parent = nullptr); - ~AdwaitaTheme() override = default; - - static AdwaitaTheme *qmlAttachedProperties(QObject *object); - - // Button - int buttonMarginHeight() const - { - return Adwaita::Button_MarginHeight; - } - int buttonMarginWidth() const - { - return Adwaita::Button_MarginWidth; - } - int buttonMinimumHeight() const - { - return Adwaita::Button_MinHeight; - } - int buttonMinimumWidth() const - { - return Adwaita::Button_MinWidth; - } - int buttonItemSpacing() const - { - return Adwaita::Button_ItemSpacing; - } - - // Checkbox - int checkboxItemSpacing() const - { - return Adwaita::CheckBox_ItemSpacing; - } - int checkboxFocusMarginWidth() const - { - return Adwaita::CheckBox_FocusMarginWidth; - } - int checkboxSize() const - { - return Adwaita::CheckBox_Size; - } - - // ComboBox - int comboBoxMarginHeight() const - { - return Adwaita::ComboBox_MarginHeight; - } - int comboBoxMarginWidth() const - { - return Adwaita::ComboBox_MarginWidth; - } - int comboBoxMinimumHeight() const - { - return Adwaita::ComboBox_MinHeight; - } - int comboBoxMinimumWidth() const - { - return Adwaita::ComboBox_MinWidth; - } - - // Frame - int frameRadius() const - { - return Adwaita::Frame_FrameRadius; - } - int frameWidth() const - { - return Adwaita::Frame_FrameWidth; - } - - // LineEdit - int lineEditFrameWidth() const - { - return Adwaita::LineEdit_FrameWidth; - } - int lineEditMarginHeight() const - { - return Adwaita::LineEdit_MarginHeight; - } - int lineEditMarginWidth() const - { - return Adwaita::LineEdit_MarginWidth; - } - int lineEditMinimumHeight() const - { - return Adwaita::LineEdit_MinHeight; - } - int lineEditMinimumWidth() const - { - return Adwaita::LineEdit_MinWidth; - } - - // MenuItem - int menuItemSpacing() const - { - return Adwaita::MenuItem_ItemSpacing; - } - int menuItemMarginWidth() const - { - return Adwaita::MenuItem_MarginWidth; - } - - // Progressbar - int progressBarBusyIndicatorSize() const - { - return Adwaita::ProgressBar_BusyIndicatorSize; - } - int progressBarThickness() const - { - return Adwaita::ProgressBar_Thickness; - } - - // Base colors - QColor baseColor() const - { - return m_palette.color(QPalette::Base); - } - QColor buttonColor() const - { - return m_palette.color(QPalette::Button); - } - QColor buttonOutlineColor() const; - QColor disabledTextColor() const - { - return m_palette.color(QPalette::Disabled, QPalette::Text); - } - QColor highlightColor() const - { - return m_palette.color(QPalette::Highlight); - } - QColor highlightTextColor() const - { - return m_palette.color(QPalette::HighlightedText); - } - QColor linkColor() const - { - return m_palette.color(QPalette::Link); - } - QColor textColor() const - { - return m_palette.color(QPalette::Text); - } - QColor windowColor() const - { - return m_palette.color(QPalette::Window); - } - - // Advanced colors - Q_INVOKABLE QColor getButtonBottomColor(bool highlighted, bool destructiveAction, bool hovered, bool pressed); - Q_INVOKABLE QColor getButtonTopColor(bool highlighted, bool destructiveAction, bool hovered, bool pressed); - Q_INVOKABLE QColor getButtonOutlineColor(bool highlighted, bool destructiveAction, bool hovered, bool pressed); - - Q_INVOKABLE QColor getCheckBoxBottomColor(bool hovered, bool pressed, bool checked); - Q_INVOKABLE QColor getCheckBoxTopColor(bool hovered, bool pressed, bool checked); - Q_INVOKABLE QColor getCheckBoxOutlineColor(bool hovered, bool pressed, bool checked); - - Q_INVOKABLE QColor getProgressBarColor(); - Q_INVOKABLE QColor getProgressBarOutlineColor(); - - Q_INVOKABLE QColor getScrollBarGrooveColor(); - Q_INVOKABLE QColor getScrollBarHandleColor(bool hovered, bool pressed); - - bool darkMode() const - { - return m_darkMode; - } - -private: - bool m_darkMode; - QPalette m_palette; -}; - -QML_DECLARE_TYPEINFO(AdwaitaTheme, QML_HAS_ATTACHED_PROPERTIES) - -#endif // ADWAITA_THEME_H diff --git a/src/theme/theme.pro b/src/theme/theme.pro deleted file mode 100644 index b20c553b..00000000 --- a/src/theme/theme.pro +++ /dev/null @@ -1,46 +0,0 @@ -TEMPLATE = lib - -CONFIG += link_pkgconfig qt plugin qmltypes -PKGCONFIG += adwaita-qt - -TARGET = adwaitathemeplugin - -QT += qml quick quickcontrols2 widgets - -CONFIG += c++11 - -HEADERS += adwaitathemeplugin.h \ - icon.h \ - theme.h - -SOURCES += adwaitathemeplugin.cpp \ - icon.cpp \ - theme.cpp - -QML_IMPORT_NAME = org.fedoraproject.AdwaitaTheme -QML_IMPORT_MAJOR_VERSION = 2 - -lupdate_only { - SOURCES += $$PWD/qml/*.qml \ - $$PWD/qml/private/*.qml \ - $$PWD/*.cpp - HEADERS += $$PWD/*.h -} - -qml.files += $$PWD/qml/*.qml -qml.path = $$[QT_INSTALL_QML]/QtQuick/Controls.2/org.fedoraproject.AdwaitaTheme - -qmlprivate.files += $$PWD/qml/private/*.qml -qmlprivate.path = $$[QT_INSTALL_QML]/QtQuick/Controls.2/org.fedoraproject.AdwaitaTheme/private - -qmldir.files += qmldir -qmldir.path = $$[QT_INSTALL_QML]/org/fedoraproject/AdwaitaTheme - -target.path = $$[QT_INSTALL_QML]/org/fedoraproject/AdwaitaTheme - -INSTALLS += target qml qmlprivate qmldir - -macx { - QMAKE_MOC_OPTIONS += -Muri=org.fedoraproject.AdwaitaTheme - QMAKE_BUNDLE_DATA += target qml qmlprivate qmldir -}