From 5e2727ce7162819d06fe449e06e0164c2977ec47 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Fri, 7 Dec 2012 15:59:59 +0400 Subject: [PATCH] Custom icons for external programs --- config.cc | 5 +++++ config.hh | 9 ++++++--- programs.cc | 19 ++++++++++++++++--- sources.cc | 11 ++++++++++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/config.cc b/config.cc index d3602ffe..958d18fd 100644 --- a/config.cc +++ b/config.cc @@ -530,6 +530,7 @@ Class load() throw( exError ) p.commandLine = pr.attribute( "commandLine" ); p.enabled = ( pr.attribute( "enabled" ) == "1" ); p.type = (Program::Type)( pr.attribute( "type" ).toInt() ); + p.iconFilename = pr.attribute( "icon" ); c.programs.push_back( p ); } @@ -1094,6 +1095,10 @@ void save( Class const & c ) throw( exError ) QDomAttr type = dd.createAttribute( "type" ); type.setValue( QString::number( i->type ) ); p.setAttributeNode( type ); + + QDomAttr icon = dd.createAttribute( "icon" ); + icon.setValue( i->iconFilename ); + p.setAttributeNode( icon ); } } diff --git a/config.hh b/config.hh index 8995fefe..98ae8471 100644 --- a/config.hh +++ b/config.hh @@ -342,20 +342,22 @@ struct Program MaxTypeValue } type; QString id, name, commandLine; + QString iconFilename; Program(): enabled( false ) {} Program( bool enabled_, Type type_, QString const & id_, - QString const & name_, QString const & commandLine_ ): + QString const & name_, QString const & commandLine_, QString iconFilename_ ): enabled( enabled_ ), type( type_ ), id( id_ ), name( name_ ), - commandLine( commandLine_ ) {} + commandLine( commandLine_ ), iconFilename( iconFilename_ ) {} bool operator == ( Program const & other ) const { return enabled == other.enabled && type == other.type && name == other.name && - commandLine == other.commandLine; + commandLine == other.commandLine && + iconFilename == other.iconFilename; } bool operator != ( Program const & other ) const @@ -381,6 +383,7 @@ struct Class unsigned lastMainGroupId; // Last used group in main window unsigned lastPopupGroupId; // Last used group in popup window + QByteArray popupWindowState; // Binary state saved by QMainWindow QByteArray popupWindowGeometry; // Geometry saved by QMainWindow QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window diff --git a/programs.cc b/programs.cc index 5740279a..162d49b5 100644 --- a/programs.cc +++ b/programs.cc @@ -8,6 +8,8 @@ #include "utf8.hh" #include "wstring_qt.hh" #include "parsecmdline.hh" +#include +#include namespace Programs { @@ -49,9 +51,7 @@ public: protected: - virtual void loadIcon() throw() - { dictionaryIcon = dictionaryNativeIcon = QIcon(":/icons/programs.png"); - dictionaryIconLoaded = true; } + virtual void loadIcon() throw(); }; sptr< WordSearchRequest > ProgramsDictionary::prefixMatch( wstring const & word, @@ -116,6 +116,19 @@ sptr< Dictionary::DataRequest > ProgramsDictionary::getArticle( } } +void ProgramsDictionary::loadIcon() throw() +{ + if( !prg.iconFilename.isEmpty() ) + { + QFileInfo fInfo( QDir( Config::getConfigDir() ), prg.iconFilename ); + if( fInfo.isFile() ) + loadIconFromFile( fInfo.absoluteFilePath(), true ); + } + if( dictionaryIcon.isNull() ) + dictionaryIcon = dictionaryNativeIcon = QIcon(":/icons/programs.png"); + dictionaryIconLoaded = true; +} + } RunInstance::RunInstance(): process( this ) diff --git a/sources.cc b/sources.cc index 82036080..14946ea9 100644 --- a/sources.cc +++ b/sources.cc @@ -58,6 +58,7 @@ Sources::Sources( QWidget * parent, Config::Paths const & paths, ProgramTypeEditor::getNameForType( Config::Program::PrefixMatch ) ) + 16 ); ui.programs->resizeColumnToContents( 2 ); ui.programs->resizeColumnToContents( 3 ); + ui.programs->resizeColumnToContents( 4 ); ui.programs->setItemDelegate( itemDelegate ); ui.paths->setTabKeyNavigation( true ); @@ -694,7 +695,7 @@ int ProgramsModel::columnCount( QModelIndex const & parent ) const if ( parent.isValid() ) return 0; else - return 4; + return 5; } QVariant ProgramsModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const @@ -710,6 +711,8 @@ QVariant ProgramsModel::headerData( int section, Qt::Orientation /*orientation*/ return tr( "Name" ); case 3: return tr( "Command Line" ); + case 4: + return tr( "Icon" ); default: return QVariant(); } @@ -735,6 +738,8 @@ QVariant ProgramsModel::data( QModelIndex const & index, int role ) const return programs[ index.row() ].name; case 3: return programs[ index.row() ].commandLine; + case 4: + return programs[ index.row() ].iconFilename; default: return QVariant(); } @@ -775,6 +780,10 @@ bool ProgramsModel::setData( QModelIndex const & index, const QVariant & value, programs[ index.row() ].commandLine = value.toString(); dataChanged( index, index ); return true; + case 4: + programs[ index.row() ].iconFilename = value.toString(); + dataChanged( index, index ); + return true; default: return false; }