From 3b3dce973acb7299499dd3527ded627940516ab3 Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 20 Jul 2005 09:52:19 +0000 Subject: [PATCH] New item (FontItem), allowing to show information about font setting and to select font from standard font dialog --- src/Qtx/QtxListResourceEdit.cxx | 58 +++++++++++++++++++++++++++++++++ src/Qtx/QtxListResourceEdit.h | 30 ++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) 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 -- 2.39.2