fixed MUSR-105, i.e. better handling of font changes, and adding the possibility to define default font and font size in musrgui_startup.xml
This commit is contained in:
parent
852eea9015
commit
5c05a34282
@ -69,7 +69,11 @@ bool PAdminXMLParser::startElement( const QString&, const QString&,
|
||||
const QString& qName,
|
||||
const QXmlAttributes& )
|
||||
{
|
||||
if (qName == "exec_path") {
|
||||
if (qName == "font_name") {
|
||||
fKeyWord = eFontName;
|
||||
} else if (qName == "font_size") {
|
||||
fKeyWord = eFontSize;
|
||||
} else if (qName == "exec_path") {
|
||||
fKeyWord = eExecPath;
|
||||
} else if (qName == "default_save_path") {
|
||||
fKeyWord = eDefaultSavePath;
|
||||
@ -141,9 +145,18 @@ bool PAdminXMLParser::endElement( const QString&, const QString&, const QString
|
||||
bool PAdminXMLParser::characters(const QString& str)
|
||||
{
|
||||
QString help;
|
||||
bool flag;
|
||||
bool flag, ok;
|
||||
int ival;
|
||||
|
||||
switch (fKeyWord) {
|
||||
case eFontName:
|
||||
fAdmin->setFontName(QString(str.ascii()).stripWhiteSpace());
|
||||
break;
|
||||
case eFontSize:
|
||||
ival = QString(str.ascii()).stripWhiteSpace().toInt(&ok);
|
||||
if (ok)
|
||||
fAdmin->setFontSize(ival);
|
||||
break;
|
||||
case eExecPath:
|
||||
fAdmin->setExecPath(QString(str.ascii()).stripWhiteSpace());
|
||||
break;
|
||||
@ -301,6 +314,9 @@ QString PAdminXMLParser::expandPath(const QString &str)
|
||||
*/
|
||||
PAdmin::PAdmin()
|
||||
{
|
||||
fFontName = QString("Courier"); // default font
|
||||
fFontSize = 11; // default font size
|
||||
|
||||
fExecPath = QString("");
|
||||
fDefaultSavePath = QString("");
|
||||
fMsrDefaultFilePath = QString("");
|
||||
|
@ -57,7 +57,7 @@ class PAdminXMLParser : public QXmlDefaultHandler
|
||||
virtual ~PAdminXMLParser() {}
|
||||
|
||||
private:
|
||||
enum EAdminKeyWords {eEmpty, eExecPath, eDefaultSavePath, eTitleFromDataFile, eEnableMusrT0,
|
||||
enum EAdminKeyWords {eEmpty, eFontName, eFontSize, eExecPath, eDefaultSavePath, eTitleFromDataFile, eEnableMusrT0,
|
||||
eBeamline, eInstitute, eFileFormat, eLifetimeCorrection, eMsrDefaultFilePath,
|
||||
eHelpMain, eTheoFuncPixmapPath, eFunc, eFuncName, eFuncComment, eFuncLabel,
|
||||
eFuncPixmap, eFuncParams};
|
||||
@ -85,6 +85,8 @@ class PAdmin
|
||||
PAdmin();
|
||||
virtual ~PAdmin() {}
|
||||
|
||||
QString getFontName() { return fFontName; }
|
||||
int getFontSize() { return fFontSize; }
|
||||
QString getExecPath() { return fExecPath; }
|
||||
QString getDefaultSavePath() { return fDefaultSavePath; }
|
||||
bool getTitleFromDataFileFlag() { return fTitleFromDataFile; }
|
||||
@ -99,6 +101,9 @@ class PAdmin
|
||||
unsigned int getTheoryCounts() { return fTheory.size(); }
|
||||
PTheory* getTheoryItem(const unsigned int idx);
|
||||
|
||||
void setFontName(const QString str) { fFontName = str; }
|
||||
void setFontSize(const int ival) { fFontSize = ival; }
|
||||
|
||||
protected:
|
||||
void setExecPath(const QString str) { fExecPath = str; }
|
||||
void setDefaultSavePath(const QString str) { fDefaultSavePath = str; }
|
||||
@ -116,6 +121,9 @@ class PAdmin
|
||||
private:
|
||||
friend class PAdminXMLParser;
|
||||
|
||||
QString fFontName;
|
||||
int fFontSize;
|
||||
|
||||
QString fExecPath;
|
||||
QString fDefaultSavePath;
|
||||
QString fMsrDefaultFilePath;
|
||||
|
@ -129,8 +129,8 @@ PTextEdit::PTextEdit( QWidget *parent, const char *name )
|
||||
fTabWidget = new QTabWidget( this );
|
||||
setCentralWidget( fTabWidget );
|
||||
|
||||
textFamily("Courier");
|
||||
textSize("11"); // 11pt
|
||||
textFamily(fAdmin->getFontName());
|
||||
textSize(QString("%1").arg(fAdmin->getFontSize()));
|
||||
|
||||
QImage img(musrfit_xpm);
|
||||
QPixmap image0 = img;
|
||||
@ -144,6 +144,7 @@ PTextEdit::PTextEdit( QWidget *parent, const char *name )
|
||||
}
|
||||
|
||||
connect( fTabWidget, SIGNAL( currentChanged(QWidget*) ), this, SLOT( checkIfModified(QWidget*) ));
|
||||
connect( fTabWidget, SIGNAL( currentChanged(QWidget*) ), this, SLOT( applyFontSettings(QWidget*) ));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -308,7 +309,7 @@ void PTextEdit::setupTextActions()
|
||||
fComboFont->insertStringList( db.families() );
|
||||
connect( fComboFont, SIGNAL( activated( const QString & ) ),
|
||||
this, SLOT( textFamily( const QString & ) ) );
|
||||
fComboFont->lineEdit()->setText( "Courier" );
|
||||
fComboFont->lineEdit()->setText( fAdmin->getFontName() );
|
||||
|
||||
fComboSize = new QComboBox( TRUE, tb );
|
||||
QValueList<int> sizes = db.standardSizes();
|
||||
@ -317,7 +318,7 @@ void PTextEdit::setupTextActions()
|
||||
fComboSize->insertItem( QString::number( *it ) );
|
||||
connect( fComboSize, SIGNAL( activated( const QString & ) ),
|
||||
this, SLOT( textSize( const QString & ) ) );
|
||||
fComboSize->lineEdit()->setText( "11" ); // 11pt font size
|
||||
fComboSize->lineEdit()->setText( QString("%1").arg(fAdmin->getFontSize()) );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -422,9 +423,9 @@ void PTextEdit::load( const QString &f, const int index )
|
||||
PSubTextEdit *edit = new PSubTextEdit( fAdmin );
|
||||
edit->setLastModified(info.lastModified());
|
||||
edit->setTextFormat( PlainText );
|
||||
edit->setFamily("Courier");
|
||||
edit->setPointSize(11); // 11pt
|
||||
edit->setFont(QFont("Courier", 11));
|
||||
edit->setFamily(fAdmin->getFontName());
|
||||
edit->setPointSize(fAdmin->getFontSize());
|
||||
edit->setFont(QFont(fAdmin->getFontName(), fAdmin->getFontSize()));
|
||||
|
||||
if (index == -1)
|
||||
fTabWidget->addTab( edit, QFileInfo( f ).fileName() );
|
||||
@ -513,8 +514,8 @@ void PTextEdit::fileNew()
|
||||
{
|
||||
PSubTextEdit *edit = new PSubTextEdit( fAdmin );
|
||||
edit->setTextFormat( PlainText );
|
||||
edit->setFamily("Courier");
|
||||
edit->setPointSize(11); // 11pt
|
||||
edit->setFamily(fAdmin->getFontName());
|
||||
edit->setPointSize(fAdmin->getFontSize());
|
||||
doConnections( edit );
|
||||
fTabWidget->addTab( edit, tr( "noname" ) );
|
||||
fTabWidget->showPage( edit );
|
||||
@ -1093,8 +1094,11 @@ void PTextEdit::editComment()
|
||||
*/
|
||||
void PTextEdit::textFamily( const QString &f )
|
||||
{
|
||||
fAdmin->setFontName(f);
|
||||
|
||||
if ( !currentEditor() )
|
||||
return;
|
||||
|
||||
currentEditor()->setFamily( f );
|
||||
currentEditor()->viewport()->setFocus();
|
||||
}
|
||||
@ -1105,9 +1109,12 @@ void PTextEdit::textFamily( const QString &f )
|
||||
*/
|
||||
void PTextEdit::textSize( const QString &p )
|
||||
{
|
||||
fAdmin->setFontSize(p.toInt());
|
||||
|
||||
if ( !currentEditor() )
|
||||
return;
|
||||
currentEditor()->setPointSize( p.toInt() );
|
||||
|
||||
currentEditor()->setPointSize(p.toInt());
|
||||
currentEditor()->viewport()->setFocus();
|
||||
}
|
||||
|
||||
@ -1843,13 +1850,17 @@ void PTextEdit::helpAboutQt()
|
||||
*/
|
||||
void PTextEdit::fontChanged( const QFont &f )
|
||||
{
|
||||
fFontChanging = true;
|
||||
currentEditor()->selectAll();
|
||||
fComboFont->lineEdit()->setText( f.family() );
|
||||
fComboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
|
||||
currentEditor()->setFamily( f.family() );
|
||||
currentEditor()->setModified(false);
|
||||
currentEditor()->setPointSize( f.pointSize() );
|
||||
currentEditor()->setModified(false);
|
||||
currentEditor()->viewport()->setFocus();
|
||||
currentEditor()->selectAll(false);
|
||||
fFontChanging = false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -1861,6 +1872,9 @@ void PTextEdit::textChanged(const bool forced)
|
||||
if (!currentEditor())
|
||||
return;
|
||||
|
||||
if (fFontChanging)
|
||||
return;
|
||||
|
||||
QString tabLabel = fTabWidget->label(fTabWidget->currentPageIndex());
|
||||
|
||||
if ((fTabWidget->label(fTabWidget->currentPageIndex()).find("*") > 0) &&
|
||||
@ -1943,6 +1957,16 @@ void PTextEdit::replaceAll()
|
||||
currentEditor()->setCursorPosition(currentPara, currentIndex);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PTextEdit::applyFontSettings(QWidget*)
|
||||
{
|
||||
QFont font(fAdmin->getFontName(), fAdmin->getFontSize());
|
||||
fontChanged(font);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
|
@ -117,6 +117,7 @@ private slots:
|
||||
void replaceAndClose();
|
||||
void replaceAll();
|
||||
|
||||
void applyFontSettings(QWidget*);
|
||||
void checkIfModified(QWidget*);
|
||||
|
||||
private:
|
||||
@ -134,6 +135,7 @@ private:
|
||||
|
||||
QComboBox *fComboFont;
|
||||
QComboBox *fComboSize;
|
||||
bool fFontChanging; ///< flag needed to prevent some textChanged feature to occure when only the font changed
|
||||
|
||||
QTabWidget *fTabWidget;
|
||||
QMap<PSubTextEdit*, QString> fFilenames;
|
||||
|
@ -11,6 +11,10 @@
|
||||
<title_from_data_file>n</title_from_data_file>
|
||||
<enable_musrt0>n</enable_musrt0>
|
||||
</general>
|
||||
<font_settings>
|
||||
<font_name>Courier</font_name>
|
||||
<font_size>12</font_size>
|
||||
</font_settings>
|
||||
<msr_file_defaults>
|
||||
<beamline>mue4</beamline>
|
||||
<institute>psi</institute>
|
||||
|
Loading…
x
Reference in New Issue
Block a user