mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +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.commandLine = pr.attribute( "commandLine" );
|
||||||
p.enabled = ( pr.attribute( "enabled" ) == "1" );
|
p.enabled = ( pr.attribute( "enabled" ) == "1" );
|
||||||
p.type = (Program::Type)( pr.attribute( "type" ).toInt() );
|
p.type = (Program::Type)( pr.attribute( "type" ).toInt() );
|
||||||
|
p.iconFilename = pr.attribute( "icon" );
|
||||||
|
|
||||||
c.programs.push_back( p );
|
c.programs.push_back( p );
|
||||||
}
|
}
|
||||||
|
@ -1094,6 +1095,10 @@ void save( Class const & c ) throw( exError )
|
||||||
QDomAttr type = dd.createAttribute( "type" );
|
QDomAttr type = dd.createAttribute( "type" );
|
||||||
type.setValue( QString::number( i->type ) );
|
type.setValue( QString::number( i->type ) );
|
||||||
p.setAttributeNode( type );
|
p.setAttributeNode( type );
|
||||||
|
|
||||||
|
QDomAttr icon = dd.createAttribute( "icon" );
|
||||||
|
icon.setValue( i->iconFilename );
|
||||||
|
p.setAttributeNode( icon );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -342,20 +342,22 @@ struct Program
|
||||||
MaxTypeValue
|
MaxTypeValue
|
||||||
} type;
|
} type;
|
||||||
QString id, name, commandLine;
|
QString id, name, commandLine;
|
||||||
|
QString iconFilename;
|
||||||
|
|
||||||
Program(): enabled( false )
|
Program(): enabled( false )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Program( bool enabled_, Type type_, QString const & id_,
|
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_ ),
|
enabled( enabled_ ), type( type_ ), id( id_ ), name( name_ ),
|
||||||
commandLine( commandLine_ ) {}
|
commandLine( commandLine_ ), iconFilename( iconFilename_ ) {}
|
||||||
|
|
||||||
bool operator == ( Program const & other ) const
|
bool operator == ( Program const & other ) const
|
||||||
{ return enabled == other.enabled &&
|
{ return enabled == other.enabled &&
|
||||||
type == other.type &&
|
type == other.type &&
|
||||||
name == other.name &&
|
name == other.name &&
|
||||||
commandLine == other.commandLine;
|
commandLine == other.commandLine &&
|
||||||
|
iconFilename == other.iconFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator != ( Program const & other ) const
|
bool operator != ( Program const & other ) const
|
||||||
|
@ -381,6 +383,7 @@ struct Class
|
||||||
|
|
||||||
unsigned lastMainGroupId; // Last used group in main window
|
unsigned lastMainGroupId; // Last used group in main window
|
||||||
unsigned lastPopupGroupId; // Last used group in popup window
|
unsigned lastPopupGroupId; // Last used group in popup window
|
||||||
|
|
||||||
QByteArray popupWindowState; // Binary state saved by QMainWindow
|
QByteArray popupWindowState; // Binary state saved by QMainWindow
|
||||||
QByteArray popupWindowGeometry; // Geometry saved by QMainWindow
|
QByteArray popupWindowGeometry; // Geometry saved by QMainWindow
|
||||||
QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window
|
QByteArray dictInfoGeometry; // Geometry of "Dictionary info" window
|
||||||
|
|
19
programs.cc
19
programs.cc
|
@ -8,6 +8,8 @@
|
||||||
#include "utf8.hh"
|
#include "utf8.hh"
|
||||||
#include "wstring_qt.hh"
|
#include "wstring_qt.hh"
|
||||||
#include "parsecmdline.hh"
|
#include "parsecmdline.hh"
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
namespace Programs {
|
namespace Programs {
|
||||||
|
|
||||||
|
@ -49,9 +51,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void loadIcon() throw()
|
virtual void loadIcon() throw();
|
||||||
{ dictionaryIcon = dictionaryNativeIcon = QIcon(":/icons/programs.png");
|
|
||||||
dictionaryIconLoaded = true; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sptr< WordSearchRequest > ProgramsDictionary::prefixMatch( wstring const & word,
|
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 )
|
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 );
|
ProgramTypeEditor::getNameForType( Config::Program::PrefixMatch ) ) + 16 );
|
||||||
ui.programs->resizeColumnToContents( 2 );
|
ui.programs->resizeColumnToContents( 2 );
|
||||||
ui.programs->resizeColumnToContents( 3 );
|
ui.programs->resizeColumnToContents( 3 );
|
||||||
|
ui.programs->resizeColumnToContents( 4 );
|
||||||
ui.programs->setItemDelegate( itemDelegate );
|
ui.programs->setItemDelegate( itemDelegate );
|
||||||
|
|
||||||
ui.paths->setTabKeyNavigation( true );
|
ui.paths->setTabKeyNavigation( true );
|
||||||
|
@ -694,7 +695,7 @@ int ProgramsModel::columnCount( QModelIndex const & parent ) const
|
||||||
if ( parent.isValid() )
|
if ( parent.isValid() )
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return 4;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ProgramsModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
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" );
|
return tr( "Name" );
|
||||||
case 3:
|
case 3:
|
||||||
return tr( "Command Line" );
|
return tr( "Command Line" );
|
||||||
|
case 4:
|
||||||
|
return tr( "Icon" );
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -735,6 +738,8 @@ QVariant ProgramsModel::data( QModelIndex const & index, int role ) const
|
||||||
return programs[ index.row() ].name;
|
return programs[ index.row() ].name;
|
||||||
case 3:
|
case 3:
|
||||||
return programs[ index.row() ].commandLine;
|
return programs[ index.row() ].commandLine;
|
||||||
|
case 4:
|
||||||
|
return programs[ index.row() ].iconFilename;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -775,6 +780,10 @@ bool ProgramsModel::setData( QModelIndex const & index, const QVariant & value,
|
||||||
programs[ index.row() ].commandLine = value.toString();
|
programs[ index.row() ].commandLine = value.toString();
|
||||||
dataChanged( index, index );
|
dataChanged( index, index );
|
||||||
return true;
|
return true;
|
||||||
|
case 4:
|
||||||
|
programs[ index.row() ].iconFilename = value.toString();
|
||||||
|
dataChanged( index, index );
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue