From: asl Date: Wed, 20 Jul 2005 09:52:19 +0000 (+0000) Subject: New item (FontItem), allowing to show information about font setting and to select... X-Git-Tag: V3_0_1~34 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3b3dce973acb7299499dd3527ded627940516ab3;p=modules%2Fgui.git New item (FontItem), allowing to show information about font setting and to select font from standard font dialog --- diff --git a/src/Qtx/QtxListResourceEdit.cxx b/src/Qtx/QtxListResourceEdit.cxx index 8ff32d4b4..bb6bfccaf 100644 --- a/src/Qtx/QtxListResourceEdit.cxx +++ b/src/Qtx/QtxListResourceEdit.cxx @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "QtxIntSpinBox.h" #include "QtxDblSpinBox.h" @@ -359,6 +361,9 @@ QtxResourceEdit::Item* QtxListResourceEdit::Group::createItem( const QString& ti case Space: item = new Spacer( resourceEdit(), this, this ); break; + case Font: + item = new FontItem( title, resourceEdit(), this, this ); + break; } return item; @@ -803,3 +808,56 @@ void QtxListResourceEdit::ColorItem::retrieve() { myColor->setPaletteBackgroundColor( getColor() ); } + + +/* + Class: QtxListResourceEdit::FontItem + Descr: GUI implementation of resources font item. +*/ +QtxListResourceEdit::FontItem::FontItem( const QString& title, QtxResourceEdit* edit, Item* pItem, QWidget* parent ) +: PrefItem( Font, edit, pItem, parent ) +{ + new QLabel( title, this ); + myFontPrs = new QLabel( "", this ); + QPushButton* selFont = new QPushButton( "..", this ); + connect( selFont, SIGNAL( clicked() ), this, SLOT( onSelectFont() ) ); +} + +QtxListResourceEdit::FontItem::~FontItem() +{ +} + +void QtxListResourceEdit::FontItem::store() +{ + Item::setFont( myFont ); +} + +void QtxListResourceEdit::FontItem::retrieve() +{ + myFont = getFont(); + buildFontPrs(); +} + +void QtxListResourceEdit::FontItem::buildFontPrs() +{ + QStringList fval; + fval.append( myFont.family() ); + if( myFont.bold() ) + fval.append( "Bold" ); + if( myFont.italic() ) + fval.append( "Italic" ); + fval.append( QString( "%1" ).arg( myFont.pointSize() ) ); + + myFontPrs->setText( fval.join( ", " ) ); +} + +void QtxListResourceEdit::FontItem::onSelectFont() +{ + bool ok; + QFont newFont = QFontDialog::getFont( &ok, myFont, this ); + if( ok ) + { + myFont = newFont; + buildFontPrs(); + } +} diff --git a/src/Qtx/QtxListResourceEdit.h b/src/Qtx/QtxListResourceEdit.h index 96a7ddd5b..13afe8187 100644 --- a/src/Qtx/QtxListResourceEdit.h +++ b/src/Qtx/QtxListResourceEdit.h @@ -46,8 +46,9 @@ public: class DoubleEditItem; class IntegerSpinItem; class IntegerEditItem; + class FontItem; - enum { Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer }; + enum { Space, Bool, Color, String, Selector, DblSpin, IntSpin, Double, Integer, Font, User }; public: QtxListResourceEdit( QtxResourceMgr*, QWidget* = 0 ); @@ -350,4 +351,31 @@ private: QWidget* myColor; }; +/* + Class: QtxListResourceEdit::FontItem + Descr: GUI implementation of resources font item. +*/ + +class QtxListResourceEdit::FontItem : public PrefItem +{ + Q_OBJECT + +public: + FontItem( const QString&, QtxResourceEdit*, Item*, QWidget* = 0 ); + virtual ~FontItem(); + + virtual void store(); + virtual void retrieve(); + +protected slots: + void onSelectFont(); + +protected: + void buildFontPrs(); + +private: + QFont myFont; + QLabel* myFontPrs; +}; + #endif