1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "QtxPopupMenu.h"
24 Class: QtxPopupMenu::TitleMenuItem [Internal]
25 Descr: Custom menu item for popup title.
28 class QtxPopupMenu::TitleMenuItem : public QCustomMenuItem
31 TitleMenuItem( const QString&, const QIconSet&, const int );
32 virtual ~TitleMenuItem();
34 virtual bool fullSpan() const;
35 virtual bool isSeparator() const;
36 virtual void setFont( const QFont& );
38 virtual void paint( QPainter*, const QColorGroup&, bool, bool, int, int, int, int );
39 virtual QSize sizeHint();
48 QtxPopupMenu::TitleMenuItem::TitleMenuItem( const QString& txt, const QIconSet& ico, const int align )
56 QtxPopupMenu::TitleMenuItem::~TitleMenuItem()
60 bool QtxPopupMenu::TitleMenuItem::fullSpan() const
65 bool QtxPopupMenu::TitleMenuItem::isSeparator() const
70 void QtxPopupMenu::TitleMenuItem::setFont( const QFont& font )
73 myFont.setBold( true );
76 void QtxPopupMenu::TitleMenuItem::paint( QPainter* p, const QColorGroup& cg,
77 bool act, bool enabled, int x, int y, int w, int h )
82 p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark ) );
84 p->setPen( cg.shadow() );
85 p->drawRect( x, y, w, h );
89 int iw = p->fontMetrics().width( myText ) + ( myIcon.isNull() ? 0 : myIcon.pixmap().width() + s );
90 int ih = QMAX( ( myIcon.isNull() ? 0 : myIcon.pixmap().height() ), p->fontMetrics().height() );
95 if ( myAlign & AlignLeft )
97 else if ( myAlign & AlignRight )
99 else if ( myAlign & AlignHCenter )
100 ix = x + ( w - iw ) / 2;
102 if ( myAlign & AlignTop )
104 else if ( myAlign & AlignBottom )
105 iy = y + ( h - ih - m );
106 else if ( myAlign & AlignVCenter )
107 iy = y + ( h - ih ) / 2;
109 if ( !myIcon.isNull() )
111 p->drawPixmap( ix, iy + ( ih - myIcon.pixmap().height() ) / 2, myIcon.pixmap() );
112 ix += myIcon.pixmap().width() + s;
115 p->setPen( cg.brightText() );
116 p->drawText( ix, iy + ( ih - p->fontMetrics().height() ) / 2 +
117 p->fontMetrics().ascent(), myText, 0, -1 );
122 QSize QtxPopupMenu::TitleMenuItem::sizeHint()
124 QFontMetrics fM( myFont );
128 int w = fM.width( myText ) + ( myIcon.isNull() ? 0 : myIcon.pixmap().width() + s );
129 int h = QMAX( ( myIcon.isNull() ? 0 : myIcon.pixmap().height() ), fM.height() ) + 2 * m;
131 return QSize( w, h );
135 Class: QtxPopupMenu [Public]
136 Descr: Popup menu item with title.
139 QtxPopupMenu::QtxPopupMenu( QWidget* parent, const char* name )
140 : QPopupMenu( parent, name ),
142 myPolicy( TitleAuto ),
143 myAlign( AlignCenter )
147 QtxPopupMenu::~QtxPopupMenu()
151 QString QtxPopupMenu::titleText() const
156 QIconSet QtxPopupMenu::titleIcon() const
161 int QtxPopupMenu::titlePolicy() const
166 int QtxPopupMenu::titleAlignment() const
171 void QtxPopupMenu::setTitleText( const QString& txt )
181 void QtxPopupMenu::setTitleIcon( const QIconSet& ico )
188 void QtxPopupMenu::setTitlePolicy( const int p )
198 void QtxPopupMenu::setTitleAlignment( const int a )
208 void QtxPopupMenu::show()
215 void QtxPopupMenu::hide()
222 QtxPopupMenu::TitleMenuItem* QtxPopupMenu::createTitleItem( const QString& txt, const QIconSet& ico,
223 const int align ) const
225 return new TitleMenuItem( txt, ico, align );
228 void QtxPopupMenu::insertTitle()
230 if ( myId != -1 || titlePolicy() == TitleOff ||
231 ( titlePolicy() == TitleAuto && titleText().stripWhiteSpace().isEmpty() ) )
234 TitleMenuItem* item = createTitleItem( titleText(), titleIcon(), titleAlignment() );
236 myId = insertItem( item, -1, 0 );
237 setItemEnabled( myId, false );
240 void QtxPopupMenu::removeTitle()
249 void QtxPopupMenu::updateTitle()