From 77467ab69b81fd6016b504342e94b2f65ce5946b Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Sat, 6 Jul 2019 02:35:03 -0400 Subject: [PATCH] tycho: use a getIcon function for QIcons --- tycho/CMakeLists.txt | 1 + tycho/cc/main.cc | 5 ----- tycho/cc/mapmodel.cc | 5 +---- tycho/cc/menu.cc | 10 ++++++---- tycho/cc/tycho.h | 2 ++ tycho/cc/utility.cc | 21 +++++++++++++++++++++ tycho/resources/resources.qrc | 8 ++++---- tycho/source/gui/mapmodel.rs | 2 +- tycho/ui/menu.ui | 7 ------- 9 files changed, 36 insertions(+), 25 deletions(-) create mode 100644 tycho/cc/utility.cc diff --git a/tycho/CMakeLists.txt b/tycho/CMakeLists.txt index 203c37c..efe29d5 100644 --- a/tycho/CMakeLists.txt +++ b/tycho/CMakeLists.txt @@ -35,6 +35,7 @@ add_library( cc/menu.cc cc/project.cc cc/tycho.h + cc/utility.cc resources/resources.qrc ui/about.ui ui/license.ui diff --git a/tycho/cc/main.cc b/tycho/cc/main.cc index 23ac24a..9e81bf7 100644 --- a/tycho/cc/main.cc +++ b/tycho/cc/main.cc @@ -1,11 +1,6 @@ #include "tycho.h" extern "C" { - void critical_msg(char const *title, char const *msg) - { - QMessageBox::critical(nullptr, QObject::tr(title), QObject::tr(msg)); - } - int main_cc(char *app_path) { dbgPrint("cc entry"); diff --git a/tycho/cc/mapmodel.cc b/tycho/cc/mapmodel.cc index 17c746d..1c92fe1 100644 --- a/tycho/cc/mapmodel.cc +++ b/tycho/cc/mapmodel.cc @@ -31,10 +31,7 @@ QVariant MapModel::data(const QModelIndex &index, int role) const { switch(role) { case Qt::DecorationRole: { - auto name = propIcon(index.row()); - auto icon = name.front() == ':' ? QIcon(name) - : QIcon::fromTheme(name); - return QVariant::fromValue(icon); + return QVariant::fromValue(::getIcon(propIcon(index.row()))); } default: return IMapModel::data(index, role); diff --git a/tycho/cc/menu.cc b/tycho/cc/menu.cc index 5b2c5be..43e5554 100644 --- a/tycho/cc/menu.cc +++ b/tycho/cc/menu.cc @@ -5,6 +5,8 @@ Menu::Menu(QWidget *parent) : { setupUi(this); + setWindowIcon(::getIcon("pfhor-hand")); + actionAbout->setShortcut(QKeySequence(QKeySequence::HelpContents)); actionClose->setShortcut(QKeySequence(QKeySequence::Close)); actionMapProps->setShortcut(QKeySequence(tr("Ctrl+P"))); @@ -58,10 +60,10 @@ void Menu::openAbout() auto text = ui.labelText->text(); text.replace("AUTHORS", - tr(tychoAuthors()).replace(':', ", ").toHtmlEscaped()); - text.replace("HOMEPAGE", tr(tychoHomepage())); - text.replace("REPOSITORY", tr(tychoRepository())); - text.replace("VERSION", tr(tychoVersion())); + tr(::tychoAuthors()).replace(':', ", ").toHtmlEscaped()); + text.replace("HOMEPAGE", tr(::tychoHomepage())); + text.replace("REPOSITORY", tr(::tychoRepository())); + text.replace("VERSION", tr(::tychoVersion())); ui.labelText->setText(text); diff --git a/tycho/cc/tycho.h b/tycho/cc/tycho.h index ad63b8d..aa8a124 100644 --- a/tycho/cc/tycho.h +++ b/tycho/cc/tycho.h @@ -159,6 +159,8 @@ std::uint32_t fourCC(byte a, byte b, byte c, byte d) static_cast(d); } +QIcon getIcon(QString const &name); + extern "C" { char const *tychoAuthors(); char const *tychoHomepage(); diff --git a/tycho/cc/utility.cc b/tycho/cc/utility.cc new file mode 100644 index 0000000..f7b3d46 --- /dev/null +++ b/tycho/cc/utility.cc @@ -0,0 +1,21 @@ +#include "tycho.h" + +QIcon getIcon(QString const &name) +{ + auto res = ":/tycho/icons/" + name + ".png"; + + if(QFile(res).exists()) { + return QIcon(res); + } else { + return QIcon::fromTheme(name); + } +} + +extern "C" { + void critical_msg(char const *title, char const *msg) + { + QMessageBox::critical(nullptr, QObject::tr(title), QObject::tr(msg)); + } +} + +// EOF diff --git a/tycho/resources/resources.qrc b/tycho/resources/resources.qrc index f1d669c..d8e109d 100644 --- a/tycho/resources/resources.qrc +++ b/tycho/resources/resources.qrc @@ -1,9 +1,9 @@ - icons/lines.png - icons/map.png - icons/points.png - icons/polygons.png + icons/lines.png + icons/map.png + icons/points.png + icons/polygons.png icons/pfhor-hand.png images/tycho1.png images/tycho2.png diff --git a/tycho/source/gui/mapmodel.rs b/tycho/source/gui/mapmodel.rs index 03ba338..60a08ef 100644 --- a/tycho/source/gui/mapmodel.rs +++ b/tycho/source/gui/mapmodel.rs @@ -52,7 +52,7 @@ impl IMapModelTrait for IMapModel { match self.get(index.into()).1.get_type() { EntryType::Image => "image-x-generic".to_string(), - EntryType::Map => ":/tycho/icons/map.png".to_string(), + EntryType::Map => "tycho-map".to_string(), EntryType::Other => "image-missing".to_string(), EntryType::Physics => "applications-system".to_string(), } diff --git a/tycho/ui/menu.ui b/tycho/ui/menu.ui index c707c06..ce02e84 100644 --- a/tycho/ui/menu.ui +++ b/tycho/ui/menu.ui @@ -19,10 +19,6 @@ Tycho - - - :/tycho/icons/pfhor-hand.png:/tycho/icons/pfhor-hand.png - @@ -153,9 +149,6 @@ - - - actionMapProps