mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Custom icons for external programs
This commit is contained in:
parent
faad6d2581
commit
5e2727ce71
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
19
programs.cc
19
programs.cc
|
@ -8,6 +8,8 @@
|
|||
#include "utf8.hh"
|
||||
#include "wstring_qt.hh"
|
||||
#include "parsecmdline.hh"
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
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 )
|
||||
|
|
11
sources.cc
11
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue