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