diff --git a/kmymoney/icons/icons.cpp b/kmymoney/icons/icons.cpp index a165c7551..9b1008863 100644 --- a/kmymoney/icons/icons.cpp +++ b/kmymoney/icons/icons.cpp @@ -1,556 +1,558 @@ /*************************************************************************** icons.cpp ------------------- begin : Sun Jun 25 2017 copyright : (C) 2017 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #include "icons.h" #include #include #include #include #include #include #include #include namespace Icons { QHash sStandardIcons; uint qHash(const Icon key, uint seed) { return ::qHash(static_cast(key), seed); } uint qHash(const IconSet key, uint seed) { return ::qHash(static_cast(key), seed); } struct iconDescription { Icon baseIcon; Icon overlayIcon; Qt::Corner corner; }; const QHash > iconMappings{ {Icon::AccountClosed, {{IconSet::Common, QStringLiteral("account-types-closed")}, {IconSet::Oxygen, QStringLiteral("dialog-close")}, {IconSet::Breeze, QStringLiteral("dialog-close")}}}, {Icon::ArrowDown, {{IconSet::Common, QStringLiteral("arrow-down")}, {IconSet::Tango, QStringLiteral("go-down")}}}, {Icon::ArrowLeft, {{IconSet::Common, QStringLiteral("arrow-left")}, {IconSet::Tango, QStringLiteral("go-previous")}}}, {Icon::ArrowRight, {{IconSet::Common, QStringLiteral("arrow-right")}, {IconSet::Tango, QStringLiteral("go-next")}}}, {Icon::ArrowUp, {{IconSet::Common, QStringLiteral("arrow-up")}, {IconSet::Tango, QStringLiteral("go-up")}}}, {Icon::Budget, {{IconSet::Common, QStringLiteral("budget")}, {IconSet::Oxygen, QStringLiteral("view-time-schedule-calculus")}, {IconSet::Breeze, QStringLiteral("view-time-schedule-calculus")}}}, {Icon::Calculator, {{IconSet::Common, QStringLiteral("accessories-calculator")}}}, {Icon::Configure, {{IconSet::Common, QStringLiteral("configure")}, {IconSet::Tango, QStringLiteral("preferences-system")}}}, {Icon::DialogCancel, {{IconSet::Common, QStringLiteral("dialog-cancel")}, {IconSet::Tango, QStringLiteral("stop")}}}, {Icon::DialogClose, {{IconSet::Common, QStringLiteral("dialog-close")}}}, {Icon::DialogError, {{IconSet::Common, QStringLiteral("dialog-error")}}}, {Icon::DialogInformation, {{IconSet::Common, QStringLiteral("dialog-information")}}}, {Icon::DialogOK, {{IconSet::Common, QStringLiteral("dialog-ok")}, {IconSet::Tango, QStringLiteral("finish")}}}, {Icon::DialogOKApply, {{IconSet::Common, QStringLiteral("dialog-ok-apply")}}}, {Icon::DialogWarning, {{IconSet::Common, QStringLiteral("dialog-warning")}}}, {Icon::DocumentClose, {{IconSet::Common, QStringLiteral("document-close")}, {IconSet::Tango, QStringLiteral("stop")}}}, {Icon::DocumentEdit, {{IconSet::Common, QStringLiteral("document-edit")}, {IconSet::Tango, QStringLiteral("text-editor")}}}, {Icon::DocumentExport, {{IconSet::Common, QStringLiteral("format-indent-more")}, {IconSet::Oxygen, QStringLiteral("document-export")}, {IconSet::Breeze, QStringLiteral("document-export")}}}, {Icon::DocumentImport, {{IconSet::Common, QStringLiteral("format-indent-less")}, {IconSet::Oxygen, QStringLiteral("document-import")}, {IconSet::Breeze, QStringLiteral("document-import")}}}, {Icon::DocumentNew, {{IconSet::Common, QStringLiteral("document-new")}}}, {Icon::DocumentOpen, {{IconSet::Common, QStringLiteral("document-open")}}}, {Icon::DocumentProperties, {{IconSet::Common, QStringLiteral("document-properties")}}}, {Icon::DocumentSave, {{IconSet::Common, QStringLiteral("document-save")}}}, {Icon::Download, {{IconSet::Breeze, QStringLiteral("edit-download")}, {IconSet::Common, QStringLiteral("go-down")}, {IconSet::Oxygen, QStringLiteral("download")}}}, {Icon::EditClear, {{IconSet::Common, QStringLiteral("edit-clear")}}}, {Icon::EditCopy, {{IconSet::Common, QStringLiteral("edit-copy")}}}, {Icon::EditDelete, {{IconSet::Common, QStringLiteral("edit-delete")}}}, {Icon::EditFind, {{IconSet::Common, QStringLiteral("edit-find")}}}, {Icon::EditRename, {{IconSet::Common, QStringLiteral("edit-rename")}, {IconSet::Tango, QStringLiteral("text-editor")}}}, {Icon::EditUndo, {{IconSet::Common, QStringLiteral("edit-undo")}}}, {Icon::Folder, {{IconSet::Common, QStringLiteral("folder")}}}, {Icon::GoTo, {{IconSet::Common, QStringLiteral("go-jump")}}}, {Icon::Help, {{IconSet::Common, QStringLiteral("help-contents")}}}, {Icon::HideCategories, {{IconSet::Common, QStringLiteral("hide-categories")}}}, {Icon::HideReconciled, {{IconSet::Common, QStringLiteral("hide-reconciled")}}}, {Icon::KMyMoney, {{IconSet::Common, QStringLiteral("kmymoney")}}}, {Icon::KeyEnter, {{IconSet::Common, QStringLiteral("input-keyboard")}, {IconSet::Oxygen, QStringLiteral("key-enter")}, {IconSet::Breeze, QStringLiteral("key-enter")}}}, {Icon::ListAdd, {{IconSet::Common, QStringLiteral("list-add")}}}, {Icon::ListAddTag, {{IconSet::Common, QStringLiteral("list-add-tag")}}}, {Icon::ListAddUser, {{IconSet::Common, QStringLiteral("list-add-user")}}}, {Icon::ListCollapse, {{IconSet::Common, QStringLiteral("zoom-out")}, {IconSet::Tango, QStringLiteral("list-remove")}}}, {Icon::ListExpand, {{IconSet::Common, QStringLiteral("zoom-in")}, {IconSet::Tango, QStringLiteral("list-add")}}}, {Icon::ListRemoveTag, {{IconSet::Common, QStringLiteral("list-remove-tag")}}}, {Icon::ListRemoveUser, {{IconSet::Common, QStringLiteral("list-remove-user")}}}, {Icon::MailMessage, {{IconSet::Common, QStringLiteral("internet-mail")}, {IconSet::Oxygen, QStringLiteral("mail-message")}, {IconSet::Breeze, QStringLiteral("mail-message")}}}, {Icon::MailMessageNew, {{IconSet::Common, QStringLiteral("mail-message-new")}}}, {Icon::MailReceive, {{IconSet::Common, QStringLiteral("mail-receive")}}}, {Icon::MapOnlineAccount, {{IconSet::Common, QStringLiteral("news-subscribe")}}}, {Icon::Merge, {{IconSet::Common, QStringLiteral("reconcile")}, {IconSet::Oxygen, QStringLiteral("merge")}, {IconSet::Breeze, QStringLiteral("merge")}}}, {Icon::NewSchedule, {{IconSet::Common, QStringLiteral("appointment-new")}}}, {Icon::OfficeChartLine, {{IconSet::Common, QStringLiteral("account-types-investments")}, {IconSet::Oxygen, QStringLiteral("office-chart-line")}, {IconSet::Breeze, QStringLiteral("office-chart-line")}, {IconSet::Tango, QStringLiteral("report-line")}}}, {Icon::OpenDatabase, {{IconSet::Common, QStringLiteral("svn-update")}}}, {Icon::Pause, {{IconSet::Common, QStringLiteral("media-playback-pause")}}}, {Icon::PayeeMerge, {{IconSet::Common, QStringLiteral("merge")}}}, {Icon::PayeeRename, {{IconSet::Common, QStringLiteral("user-properties")}}}, {Icon::PerformanceTest, {{IconSet::Common, QStringLiteral("fork")}}}, {Icon::PreferencesColors, {{IconSet::Common, QStringLiteral("preferences-desktop-color")}}}, {Icon::PreferencesFonts, {{IconSet::Common, QStringLiteral("preferences-desktop-font")}}}, {Icon::PreferencesGeneral, {{IconSet::Common, QStringLiteral("system-run")}, {IconSet::Tango, QStringLiteral("media-playback-start")}}}, {Icon::PreferencesIcons, {{IconSet::Common, QStringLiteral("preferences-desktop-icon")}}}, {Icon::PreferencesNetwork, {{IconSet::Common, QStringLiteral("preferences-system-network")}}}, {Icon::PreferencesPlugins, {{IconSet::Common, QStringLiteral("network-disconnect")}}}, {Icon::Reconcile, {{IconSet::Common, QStringLiteral("reconcile")}, {IconSet::Oxygen, QStringLiteral("merge")}, {IconSet::Breeze, QStringLiteral("merge")}}}, {Icon::Reconciled, {{IconSet::Common, QStringLiteral("reconciled")}, {IconSet::Oxygen, QStringLiteral("flag-green")}, {IconSet::Breeze, QStringLiteral("flag-green")}}}, {Icon::Refresh, {{IconSet::Breeze, QStringLiteral("view-refresh")}, {IconSet::Oxygen, QStringLiteral("refresh")}}}, {Icon::Report, {{IconSet::Common, QStringLiteral("application-vnd.oasis.opendocument.spreadsheet")}}}, {Icon::Reverse, {{IconSet::Common, QStringLiteral("reverse")}}}, {Icon::SeekForward, {{IconSet::Common, QStringLiteral("media-seek-forward")}}}, {Icon::SkipForward, {{IconSet::Common, QStringLiteral("media-skip-forward")}}}, {Icon::SortAscending, {{IconSet::Common, QStringLiteral("go-up")}, {IconSet::Oxygen, QStringLiteral("view-sort-ascending")}, {IconSet::Breeze, QStringLiteral("view-sort-ascending")}}}, {Icon::SortDescending, {{IconSet::Common, QStringLiteral("go-down")}, {IconSet::Oxygen, QStringLiteral("view-sort-descending")}, {IconSet::Breeze, QStringLiteral("view-sort-descending")}}}, {Icon::Split, {{IconSet::Common, QStringLiteral("transaction-split")}, {IconSet::Oxygen, QStringLiteral("split")}, {IconSet::Breeze, QStringLiteral("split")}}}, {Icon::TagRename, {{IconSet::Common, QStringLiteral("tag-rename")}}}, {Icon::TaskAccepted, {{IconSet::Common, QStringLiteral("task-accepted")}}}, {Icon::TaskAttention, {{IconSet::Common, QStringLiteral("task-attention")}, {IconSet::Tango, QStringLiteral("dialog-warning")}}}, {Icon::TaskComplete, {{IconSet::Common, QStringLiteral("task-complete")}}}, {Icon::TaskOngoing, {{IconSet::Common, QStringLiteral("task-ongoing")}}}, {Icon::TaskReject, {{IconSet::Common, QStringLiteral("task-reject")}}}, {Icon::Tip, {{IconSet::Common, QStringLiteral("info")}, {IconSet::Oxygen, QStringLiteral("ktip")}}}, {Icon::Unknown, {{IconSet::Common, QStringLiteral("unknown")}}}, {Icon::UnmapOnlineAccount, {{IconSet::Common, QStringLiteral("news-unsubscribe")}}}, {Icon::UserProperties, {{IconSet::Common, QStringLiteral("system-users")}, {IconSet::Oxygen, QStringLiteral("user-properties")}, {IconSet::Breeze, QStringLiteral("user-properties")}}}, {Icon::ViewAccounts, {{IconSet::Common, QStringLiteral("account")}, {IconSet::Oxygen, QStringLiteral("view-bank-account")}, {IconSet::Breeze, QStringLiteral("view-bank-account")}}}, {Icon::ViewAsset, {{IconSet::Common, QStringLiteral("account-types-asset")}, {IconSet::Oxygen, QStringLiteral("view-bank-account")}, {IconSet::Breeze, QStringLiteral("view-bank-account")}}}, {Icon::ViewBank, {{IconSet::Common, QStringLiteral("bank")}, {IconSet::Oxygen, QStringLiteral("view-bank")}, {IconSet::Breeze, QStringLiteral("view-bank")}}}, {Icon::ViewBankAccount, {{IconSet::Common, QStringLiteral("account")}, {IconSet::Oxygen, QStringLiteral("view-bank-account")}, {IconSet::Breeze, QStringLiteral("view-bank-account")}}}, {Icon::ViewBudgets, {{IconSet::Common, QStringLiteral("budget")}, {IconSet::Oxygen, QStringLiteral("view-time-schedule-calculus")}, {IconSet::Breeze, QStringLiteral("view-time-schedule-calculus")}}}, {Icon::ViewCalendar, {{IconSet::Common, QStringLiteral("view-calendar")}}}, {Icon::ViewCalendarDay, {{IconSet::Common, QStringLiteral("office-calendar")}, {IconSet::Oxygen, QStringLiteral("view-calendar-day")}, {IconSet::Breeze, QStringLiteral("view-calendar-day")}}}, {Icon::ViewCash, {{IconSet::Common, QStringLiteral("account-types-cash")}}}, {Icon::ViewCategories, {{IconSet::Common, QStringLiteral("categories")}, {IconSet::Oxygen, QStringLiteral("view-categories")}, {IconSet::Breeze, QStringLiteral("view-categories")}, {IconSet::Oxygen, QStringLiteral("view-financial-categories")}}}, {Icon::ViewChecking, {{IconSet::Common, QStringLiteral("account-types-checking")}, {IconSet::Oxygen, QStringLiteral("view-bank-account-checking")}, {IconSet::Breeze, QStringLiteral("view-bank-account-checking")}}}, {Icon::ViewClose, {{IconSet::Common, QStringLiteral("view-close")}}}, {Icon::ViewCreditCard, {{IconSet::Breeze, QStringLiteral("skrooge_credit_card")}, {IconSet::Common, QStringLiteral("account-types-credit-card")}, {IconSet::Oxygen, QStringLiteral("view-credit-card-account")}}}, {Icon::ViewCurrencyList, {{IconSet::Common, QStringLiteral("view-currency-list")}}}, {Icon::ViewEquity, {{IconSet::Common, QStringLiteral("account")}, {IconSet::Oxygen, QStringLiteral("view-bank-account")}, {IconSet::Breeze, QStringLiteral("view-bank-account")}}}, {Icon::ViewExpense, {{IconSet::Breeze, QStringLiteral("view-categories-expenditures")}, {IconSet::Common, QStringLiteral("account-types-expense")}, {IconSet::Oxygen, QStringLiteral("view-expenses-categories")}}}, {Icon::ViewFilter, {{IconSet::Common, QStringLiteral("view-filter")}}}, {Icon::ViewFinancialCategories, {{IconSet::Common, QStringLiteral("categories")}, {IconSet::Oxygen, QStringLiteral("view-categories")}, {IconSet::Breeze, QStringLiteral("view-categories")}, {IconSet::Oxygen, QStringLiteral("view-financial-categories")}}}, {Icon::ViewFinancialList, {{IconSet::Common, QStringLiteral("ledger")}, {IconSet::Oxygen, QStringLiteral("view-financial-list")}}}, {Icon::ViewFinancialTransfer, {{IconSet::Common, QStringLiteral("ledger")}, {IconSet::Oxygen, QStringLiteral("view-financial-transfer")}}}, {Icon::ViewForecast, {{IconSet::Common, QStringLiteral("forecast")}, {IconSet::Oxygen, QStringLiteral("view-financial-forecast")}}}, {Icon::ViewHome, {{IconSet::Common, QStringLiteral("home")}, {IconSet::Oxygen, QStringLiteral("go-home")}, {IconSet::Breeze, QStringLiteral("go-home")}}}, {Icon::ViewIncome, {{IconSet::Breeze, QStringLiteral("view-categories-incomes")}, {IconSet::Common, QStringLiteral("account-types-income")}, {IconSet::Oxygen, QStringLiteral("view-income-categories")}}}, {Icon::ViewInstitutions, {{IconSet::Common, QStringLiteral("institution")}, {IconSet::Oxygen, QStringLiteral("view-bank")}, {IconSet::Breeze, QStringLiteral("view-bank")}}}, {Icon::ViewInvestments, {{IconSet::Common, QStringLiteral("investment")}, {IconSet::Oxygen, QStringLiteral("view-investment")}}}, {Icon::ViewLedgers, {{IconSet::Common, QStringLiteral("ledger")}, {IconSet::Oxygen, QStringLiteral("view-financial-list")}}}, {Icon::ViewLiability, {{IconSet::Common, QStringLiteral("account-types-liability")}, {IconSet::Oxygen, QStringLiteral("view-loan")}}}, {Icon::ViewLoan, {{IconSet::Common, QStringLiteral("account-types-loan")}, {IconSet::Oxygen, QStringLiteral("view-loan")}}}, {Icon::ViewLoanAsset, {{IconSet::Common, QStringLiteral("account-types-loan")}, {IconSet::Oxygen, QStringLiteral("view-loan-asset")}}}, {Icon::ViewOutbox, {{IconSet::Common, QStringLiteral("online-banking")}}}, {Icon::ViewPayees, {{IconSet::Common, QStringLiteral("payee")}, {IconSet::Oxygen, QStringLiteral("system-users")}, {IconSet::Breeze, QStringLiteral("system-users")}}}, {Icon::ViewReports, {{IconSet::Common, QStringLiteral("report")}, {IconSet::Oxygen, QStringLiteral("office-chart-bar")}, {IconSet::Breeze, QStringLiteral("office-chart-bar")}}}, {Icon::ViewSaving, {{IconSet::Common, QStringLiteral("account-types-savings")}, {IconSet::Oxygen, QStringLiteral("view-bank-account-savings")}, {IconSet::Breeze, QStringLiteral("view-bank-account-savings")}}}, {Icon::ViewSchedules, {{IconSet::Common, QStringLiteral("schedule")}, {IconSet::Oxygen, QStringLiteral("view-pim-calendar")}, {IconSet::Breeze, QStringLiteral("view-pim-calendar")}}}, {Icon::ViewStock, {{IconSet::Common, QStringLiteral("account-types-investments")}, {IconSet::Oxygen, QStringLiteral("view-stock-account")}}}, {Icon::ViewTags, {{IconSet::Common, QStringLiteral("bookmark-new")}, {IconSet::Oxygen, QStringLiteral("mail-tagged")}, {IconSet::Breeze, QStringLiteral("mail-tagged")}}}, {Icon::ViewTransactionDetail, {{IconSet::Common, QStringLiteral("edit-find")}, {IconSet::Oxygen, QStringLiteral("zoom-in")}, {IconSet::Breeze, QStringLiteral("zoom-in")}}}, {Icon::ViewUpcominEvents, {{IconSet::Common, QStringLiteral("view-calendar-upcoming-events")}}}, {Icon::ZoomIn, {{IconSet::Common, QStringLiteral("zoom-in")}}}, {Icon::ZoomOut, {{IconSet::Common, QStringLiteral("zoom-out")}}}, + {Icon::Visibility, {{IconSet::Common, QStringLiteral("visibility")}}}, + {Icon::NoVisibility, {{IconSet::Common, QStringLiteral("hint")}}} }; const QHash sComposedIcons { {Icon::EditFindTransaction, {Icon::ViewFinancialTransfer, Icon::EditFind, Qt::BottomRightCorner}}, {Icon::InstitutionNew, {Icon::ViewBank, Icon::ListAdd, Qt::BottomRightCorner}}, {Icon::InstitutionEdit, {Icon::ViewBank, Icon::DocumentEdit, Qt::BottomRightCorner}}, {Icon::InstitutionDelete, {Icon::ViewBank, Icon::EditDelete, Qt::BottomRightCorner}}, {Icon::AccountNew, {Icon::ViewBankAccount, Icon::ListAdd, Qt::TopRightCorner}}, {Icon::AccountFinishReconciliation, {Icon::Merge, Icon::DialogOK, Qt::BottomRightCorner}}, {Icon::AccountEdit, {Icon::ViewBankAccount, Icon::DocumentEdit, Qt::BottomRightCorner}}, {Icon::AccountDelete, {Icon::ViewBankAccount, Icon::EditDelete, Qt::BottomRightCorner}}, {Icon::AccountClose, {Icon::ViewBankAccount, Icon::DialogClose, Qt::BottomRightCorner}}, {Icon::AccountReopen, {Icon::ViewBankAccount, Icon::DialogOK, Qt::BottomRightCorner}}, {Icon::AccountUpdateMenu, {Icon::ViewBankAccount, Icon::Download, Qt::BottomRightCorner}}, {Icon::AccountUpdate, {Icon::ViewBankAccount, Icon::Download, Qt::BottomRightCorner}}, {Icon::AccountUpdateAll, {Icon::ViewBankAccount, Icon::Download, Qt::BottomRightCorner}}, {Icon::AccountCreditTransfer, {Icon::ViewBankAccount, Icon::MailMessageNew, Qt::BottomRightCorner}}, {Icon::CategoryNew, {Icon::ViewFinancialCategories, Icon::ListAdd, Qt::TopRightCorner}}, {Icon::CategoryEdit, {Icon::ViewFinancialCategories, Icon::DocumentEdit, Qt::BottomRightCorner}}, {Icon::CategoryDelete, {Icon::ViewFinancialCategories, Icon::EditDelete, Qt::BottomRightCorner}}, {Icon::ToolUpdatePrices, {Icon::ViewInvestments, Icon::Download, Qt::BottomRightCorner}}, {Icon::TransactionNew, {Icon::ViewFinancialTransfer, Icon::ListAdd, Qt::TopRightCorner}}, {Icon::TransactionEdit, {Icon::ViewFinancialTransfer, Icon::DocumentEdit, Qt::BottomRightCorner}}, {Icon::TransactionMatch, {Icon::ViewFinancialTransfer, Icon::DocumentImport, Qt::BottomRightCorner}}, {Icon::TransactionAccept, {Icon::ViewFinancialTransfer, Icon::DialogOKApply, Qt::BottomRightCorner}}, {Icon::InvestmentNew, {Icon::ViewInvestments, Icon::ListAdd, Qt::TopRightCorner}}, {Icon::InvestmentEdit, {Icon::ViewInvestments, Icon::DocumentEdit, Qt::BottomRightCorner}}, {Icon::InvestmentDelete, {Icon::ViewInvestments, Icon::EditDelete, Qt::BottomRightCorner}}, {Icon::InvestmentOnlinePrice, {Icon::ViewInvestments, Icon::Download, Qt::BottomRightCorner}}, {Icon::BudgetNew, {Icon::Budget, Icon::ListAdd, Qt::TopRightCorner}}, {Icon::BudgetRename, {Icon::Budget, Icon::DocumentEdit, Qt::BottomRightCorner}}, {Icon::BudgetDelete, {Icon::Budget, Icon::EditDelete, Qt::BottomRightCorner}}, {Icon::BudgetCopy, {Icon::Budget, Icon::EditCopy, Qt::BottomRightCorner}}, {Icon::PriceUpdate, {Icon::ViewCurrencyList, Icon::Download, Qt::BottomRightCorner}} }; KMM_ICONS_EXPORT void setUpMappings(const QString& themeName) { for (auto iconDef = iconMappings.cbegin(); iconDef != iconMappings.cend(); ++iconDef) { const auto icon = iconDef.key(); for (auto mapping = iconDef.value().cbegin(); mapping != iconDef->cend(); ++mapping) { switch (mapping.key()) { case (IconSet::Oxygen): if (themeName.contains(QStringLiteral("oxygen"), Qt::CaseInsensitive)) { sStandardIcons.insert(icon, mapping.value()); continue; } break; case (IconSet::Tango): if (themeName.contains(QStringLiteral("tango"), Qt::CaseInsensitive)) { sStandardIcons.insert(icon, mapping.value()); continue; } break; case (IconSet::Breeze): if (themeName.contains(QStringLiteral("breeze"), Qt::CaseInsensitive)) { sStandardIcons.insert(icon, mapping.value()); continue; } break; case (IconSet::Common): sStandardIcons.insert(icon, mapping.value()); break; } } } } /** * This method overlays an icon over another one, to get a composite one * eg. an icon to add accounts */ QIcon overlayIcon(iconDescription description, const int size = 64) { const auto iconName = sStandardIcons[description.baseIcon]; const auto overlayName = sStandardIcons[description.overlayIcon]; const auto corner = description.corner; QPixmap pxIcon; QString kyIcon = iconName + overlayName; // If found in the cache, return quickly if (QPixmapCache::find(kyIcon, pxIcon)) return pxIcon; // try to retrieve the main icon from cache if (!QPixmapCache::find(iconName, pxIcon)) { pxIcon = QIcon::fromTheme(iconName).pixmap(size); QPixmapCache::insert(iconName, pxIcon); } if (overlayName.isEmpty()) // call from MyMoneyAccount::accountPixmap can have no overlay icon, so handle that appropriately return pxIcon; QPainter pixmapPainter(&pxIcon); QPixmap pxOverlay = QIcon::fromTheme(overlayName).pixmap(size); int x, y; switch (corner) { case Qt::TopLeftCorner: x = 0; y = 0; break; case Qt::TopRightCorner: x = pxIcon.width() / 2; y = 0; break; case Qt::BottomLeftCorner: x = 0; y = pxIcon.height() / 2; break; case Qt::BottomRightCorner: default: x = pxIcon.width() / 2; y = pxIcon.height() / 2; break; } pixmapPainter.drawPixmap(x, y, pxIcon.width() / 2, pxIcon.height() / 2, pxOverlay); //save for later use QPixmapCache::insert(kyIcon, pxIcon); return pxIcon; } KMM_ICONS_EXPORT QIcon get(Icon icon) { if (sComposedIcons.contains(icon)) return overlayIcon(sComposedIcons[icon]); return QIcon::fromTheme(sStandardIcons[icon]); } QString iconCacheDir() { const QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); if (QDir::root().mkpath(cachePath)) { return cachePath; } return QString(); } KMM_ICONS_EXPORT bool storeIconInApplicationCache(const QString& name, const QIcon& icon) { // split the icon name from the type QRegularExpression iconPath(QStringLiteral("^(?[a-zA-Z]+):(?.+)"), QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatch matcher = iconPath.match(name); if (matcher.hasMatch()) { if (matcher.captured(QStringLiteral("type")).compare(QLatin1String("enum")) == 0) { return true; } else { const QString cacheDir = iconCacheDir(); if (!cacheDir.isEmpty()) { return icon.pixmap(16).save(QString::fromLatin1("%1/%2-%3").arg(cacheDir, matcher.captured(QStringLiteral("type")), matcher.captured(QStringLiteral("name"))), "PNG"); } } } return false; } KMM_ICONS_EXPORT QIcon loadIconFromApplicationCache(const QString& name) { const QHash sEnumIcons { { QStringLiteral("ViewBank"), Icon::ViewBank }, }; // split the icon name from the type QRegularExpression iconPath(QStringLiteral("^(?[a-zA-Z]+):(?.+)"), QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatch matcher = iconPath.match(name); if (matcher.hasMatch()) { if (matcher.captured(QStringLiteral("type")).compare(QLatin1String("enum")) == 0) { // type is enum, so we use our own set of icons const QString iconName = matcher.captured(QStringLiteral("name")); if (sEnumIcons.contains(iconName)) { return get(sEnumIcons[iconName]); } } else { // otherwise, we use the type as part of the filename const QString cacheDir = iconCacheDir(); if (!cacheDir.isEmpty()) { const QString filename = QString::fromLatin1("%1/%2-%3").arg(cacheDir, matcher.captured(QStringLiteral("type")), matcher.captured(QStringLiteral("name"))); if (QFile::exists(filename)) { return QIcon(filename); } } } } return QIcon(); } } diff --git a/kmymoney/icons/icons.h b/kmymoney/icons/icons.h index 756da1286..d499a1d06 100644 --- a/kmymoney/icons/icons.h +++ b/kmymoney/icons/icons.h @@ -1,132 +1,132 @@ /*************************************************************************** icons.h ------------------- begin : Sun Jun 25 2017 copyright : (C) 2017 by Łukasz Wojniłowicz ***************************************************************************/ /*************************************************************************** * * * 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. * * * ***************************************************************************/ #ifndef ICONS_H #define ICONS_H // ---------------------------------------------------------------------------- // QT Includes #include // ---------------------------------------------------------------------------- // Project Includes class QString; class QIcon; namespace Icons { enum class IconSet { Common, Oxygen, Tango, Breeze }; enum class Icon { OpenDatabase, Merge, Reconcile, Split, Tip, PerformanceTest, Calculator, UserProperties, DocumentProperties, ZoomIn, ZoomOut, Pause, SeekForward, SkipForward, HideReconciled, HideCategories, ViewHome, ViewInstitutions, ViewAccounts, ViewCategories, ViewSchedules, ViewTags, ViewPayees, ViewLedgers, ViewInvestments, ViewReports, ViewBudgets, ViewForecast, ViewOutbox, ViewFilter, ViewLoan, ViewStock, ViewChecking, ViewSaving, ViewLoanAsset, ViewCreditCard, ViewCash, ViewEquity, ViewIncome, ViewExpense, ViewAsset, ViewLiability, ViewUpcominEvents, ViewCalendarDay, ViewFinancialList, ViewBankAccount, ViewCurrencyList, ViewFinancialCategories, ViewFinancialTransfer, ViewBank, Budget, ViewCalendar, ViewTransactionDetail, ViewClose, DialogOK, DialogClose, DialogCancel, DialogOKApply, DialogError, DialogWarning, DialogInformation, ListExpand, ListCollapse, ListAdd, ListAddUser, ListRemoveUser, ListAddTag, ListRemoveTag, GoTo, KeyEnter, Download, TagRename, EditDelete, EditCopy, EditRename, EditFind, EditUndo, EditClear, DocumentEdit, DocumentNew, DocumentSave, DocumentClose, DocumentOpen, DocumentImport, DocumentExport, OfficeChartLine, MailMessageNew, MailMessage, MailReceive, MapOnlineAccount, UnmapOnlineAccount, NewSchedule, KMyMoney, PayeeRename, PayeeMerge, Configure, Reconciled, AccountClosed, Unknown, Report, Refresh, PreferencesGeneral, SortAscending, SortDescending, ArrowUp, ArrowDown, ArrowRight, ArrowLeft, TaskAttention, TaskComplete, TaskReject, TaskAccepted, TaskOngoing, Help, Folder, PreferencesFonts, PreferencesColors, PreferencesIcons, PreferencesNetwork, PreferencesPlugins, Empty, EditFindTransaction, InstitutionNew, InstitutionEdit, InstitutionDelete, AccountNew, AccountEdit, AccountDelete, AccountClose, AccountReopen, AccountUpdateMenu, AccountUpdate, AccountUpdateAll, AccountCreditTransfer, AccountFinishReconciliation, CategoryNew, CategoryEdit, CategoryDelete, TransactionNew, TransactionEdit, TransactionMatch, TransactionAccept, InvestmentNew, InvestmentEdit, InvestmentDelete, InvestmentOnlinePrice, BudgetNew, BudgetRename, BudgetDelete, BudgetCopy, - PriceUpdate, ToolUpdatePrices, Reverse + PriceUpdate, ToolUpdatePrices, Reverse, Visibility, NoVisibility }; KMM_ICONS_EXPORT void setUpMappings(const QString & themeName); KMM_ICONS_EXPORT QIcon get(Icons::Icon icon); /** * return an icon from the application local cache or an icon provided * by the application. The @a name is formatted as @c type:iconName. * The following types are supported * * - enum * - favicon * * @sa storeIconInApplicationCache(const QString& name, const QIcon& icon) */ KMM_ICONS_EXPORT QIcon loadIconFromApplicationCache(const QString& name); /** * store the @a icon in the applications local cache directory under the given @a name. * The @a name is formatted as @c type:iconName. * The icon will be stored in the file "type-iconName". * * @sa loadIconFromApplicationCache(const QString& name) */ KMM_ICONS_EXPORT bool storeIconInApplicationCache(const QString& name, const QIcon& icon); } #endif diff --git a/kmymoney/widgets/passwordtoggle.cpp b/kmymoney/widgets/passwordtoggle.cpp index bbe18b956..f9c5f454e 100644 --- a/kmymoney/widgets/passwordtoggle.cpp +++ b/kmymoney/widgets/passwordtoggle.cpp @@ -1,57 +1,65 @@ /* * Copyright 2019 Thomas Baumgart * * 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, see . */ #include "passwordtoggle.h" // ---------------------------------------------------------------------------- // QT Includes #include #include // ---------------------------------------------------------------------------- // KDE Includes #include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "icons/icons.h" + +using namespace Icons; + PasswordToggle::PasswordToggle(QLineEdit* parent) : QObject(parent) , m_lineEdit(parent) { - m_toggleAction = m_lineEdit->addAction(QIcon::fromTheme(QStringLiteral("visibility")), QLineEdit::TrailingPosition); + m_toggleAction = m_lineEdit->addAction(Icons::get(Icon::Visibility), QLineEdit::TrailingPosition); m_toggleAction->setVisible(false); m_toggleAction->setToolTip(i18n("Change the visibility of the password")); connect(m_lineEdit, &QLineEdit::textChanged, this, &PasswordToggle::toggleEchoModeAction); connect(m_toggleAction, &QAction::triggered, this, &PasswordToggle::toggleEchoMode); } void PasswordToggle::toggleEchoModeAction(const QString& text) { m_toggleAction->setVisible(!text.isEmpty()); } void PasswordToggle::toggleEchoMode() { if (m_lineEdit->echoMode() == QLineEdit::Password) { m_lineEdit->setEchoMode(QLineEdit::Normal); - m_toggleAction->setIcon(QIcon::fromTheme(QStringLiteral("hint"))); + m_toggleAction->setIcon(Icons::get(Icon::NoVisibility)); } else if (m_lineEdit->echoMode() == QLineEdit::Normal) { m_lineEdit->setEchoMode(QLineEdit::Password); - m_toggleAction->setIcon(QIcon::fromTheme(QStringLiteral("visibility"))); + m_toggleAction->setIcon(Icons::get(Icon::Visibility)); } }