tycho: use a getIcon function for QIcons

master
an 2019-07-06 02:35:03 -04:00
parent f74981d814
commit 77467ab69b
9 changed files with 36 additions and 25 deletions

View File

@ -35,6 +35,7 @@ add_library(
cc/menu.cc cc/menu.cc
cc/project.cc cc/project.cc
cc/tycho.h cc/tycho.h
cc/utility.cc
resources/resources.qrc resources/resources.qrc
ui/about.ui ui/about.ui
ui/license.ui ui/license.ui

View File

@ -1,11 +1,6 @@
#include "tycho.h" #include "tycho.h"
extern "C" { 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) int main_cc(char *app_path)
{ {
dbgPrint("cc entry"); dbgPrint("cc entry");

View File

@ -31,10 +31,7 @@ QVariant MapModel::data(const QModelIndex &index, int role) const
{ {
switch(role) { switch(role) {
case Qt::DecorationRole: { case Qt::DecorationRole: {
auto name = propIcon(index.row()); return QVariant::fromValue(::getIcon(propIcon(index.row())));
auto icon = name.front() == ':' ? QIcon(name)
: QIcon::fromTheme(name);
return QVariant::fromValue(icon);
} }
default: default:
return IMapModel::data(index, role); return IMapModel::data(index, role);

View File

@ -5,6 +5,8 @@ Menu::Menu(QWidget *parent) :
{ {
setupUi(this); setupUi(this);
setWindowIcon(::getIcon("pfhor-hand"));
actionAbout->setShortcut(QKeySequence(QKeySequence::HelpContents)); actionAbout->setShortcut(QKeySequence(QKeySequence::HelpContents));
actionClose->setShortcut(QKeySequence(QKeySequence::Close)); actionClose->setShortcut(QKeySequence(QKeySequence::Close));
actionMapProps->setShortcut(QKeySequence(tr("Ctrl+P"))); actionMapProps->setShortcut(QKeySequence(tr("Ctrl+P")));
@ -58,10 +60,10 @@ void Menu::openAbout()
auto text = ui.labelText->text(); auto text = ui.labelText->text();
text.replace("AUTHORS", text.replace("AUTHORS",
tr(tychoAuthors()).replace(':', ", ").toHtmlEscaped()); tr(::tychoAuthors()).replace(':', ", ").toHtmlEscaped());
text.replace("HOMEPAGE", tr(tychoHomepage())); text.replace("HOMEPAGE", tr(::tychoHomepage()));
text.replace("REPOSITORY", tr(tychoRepository())); text.replace("REPOSITORY", tr(::tychoRepository()));
text.replace("VERSION", tr(tychoVersion())); text.replace("VERSION", tr(::tychoVersion()));
ui.labelText->setText(text); ui.labelText->setText(text);

View File

@ -159,6 +159,8 @@ std::uint32_t fourCC(byte a, byte b, byte c, byte d)
static_cast<std::uint32_t>(d); static_cast<std::uint32_t>(d);
} }
QIcon getIcon(QString const &name);
extern "C" { extern "C" {
char const *tychoAuthors(); char const *tychoAuthors();
char const *tychoHomepage(); char const *tychoHomepage();

21
tycho/cc/utility.cc Normal file
View File

@ -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

View File

@ -1,9 +1,9 @@
<RCC> <RCC>
<qresource prefix="/tycho"> <qresource prefix="/tycho">
<file alias="icons/lines.png">icons/lines.png</file> <file alias="icons/tycho-lines.png">icons/lines.png</file>
<file alias="icons/map.png">icons/map.png</file> <file alias="icons/tycho-map.png">icons/map.png</file>
<file alias="icons/points.png">icons/points.png</file> <file alias="icons/tycho-points.png">icons/points.png</file>
<file alias="icons/polygons.png">icons/polygons.png</file> <file alias="icons/tycho-polygons.png">icons/polygons.png</file>
<file alias="icons/pfhor-hand.png">icons/pfhor-hand.png</file> <file alias="icons/pfhor-hand.png">icons/pfhor-hand.png</file>
<file>images/tycho1.png</file> <file>images/tycho1.png</file>
<file>images/tycho2.png</file> <file>images/tycho2.png</file>

View File

@ -52,7 +52,7 @@ impl IMapModelTrait for IMapModel
{ {
match self.get(index.into()).1.get_type() { match self.get(index.into()).1.get_type() {
EntryType::Image => "image-x-generic".to_string(), 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::Other => "image-missing".to_string(),
EntryType::Physics => "applications-system".to_string(), EntryType::Physics => "applications-system".to_string(),
} }

View File

@ -19,10 +19,6 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Tycho</string> <string>Tycho</string>
</property> </property>
<property name="windowIcon">
<iconset resource="../resources/resources.qrc">
<normaloff>:/tycho/icons/pfhor-hand.png</normaloff>:/tycho/icons/pfhor-hand.png</iconset>
</property>
<widget class="QWidget" name="widget"> <widget class="QWidget" name="widget">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing"> <property name="spacing">
@ -153,9 +149,6 @@
</action> </action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources>
<include location="../resources/resources.qrc"/>
</resources>
<connections> <connections>
<connection> <connection>
<sender>actionMapProps</sender> <sender>actionMapProps</sender>