My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtabbutton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006 by Gopala Krishna A <krishna.ggk@gmail.com> *
3  * *
4  * This is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2, or (at your option) *
7  * any later version. *
8  * *
9  * This software is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this package; see the file COPYING. If not, write to *
16  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, *
17  * Boston, MA 02110-1301, USA. *
18  ***************************************************************************/
19 
20 #include "vtabbutton.h"
21 #include <qstring.h>
22 #include <qstyle.h>
23 #include <qpainter.h>
24 #include <qapplication.h>
25 
26 VTab::VTab(VTabPosition pos,int p_id,QWidget *p,const char* n) : QPushButton(p,n)
27 {
28  m_position = pos;
29  m_id = p_id;
30  init();
31 }
32 
33 void VTab::init()
34 {
35  setFlat(true);
36  setToggleButton(true);
37  setAutoDefault(false);
38  setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
39  connect(this,SIGNAL(toggled(bool )),SLOT(slotToggled(bool)));
40 }
41 
43 {}
44 
45 void VTab::setID(int p_id)
46 {
47  m_id = p_id;
48 }
49 
51 {
52  if(m_position != p_pos)
53  {
54  m_position = p_pos;
55  repaint();
56  }
57 }
58 
59 
60 QSize VTab::sizeHint() const
61 {
62  constPolish();
63  QString _text = text();
64  if(_text.isNull())
65  _text = "XXX";
66  QFontMetrics fm = this->fontMetrics();
67  int w = fm.height()+5;
68  int h = 24+fm.width(_text);
69  return style().sizeFromContents(QStyle::CT_ToolButton, this,
70  QSize(w, h)).expandedTo(QApplication::globalStrut());
71 }
72 
73 void VTab::drawButton(QPainter *p)
74 {
75  p->save();
76  QStyle::SFlags st = QStyle::Style_Default | QStyle::Style_Enabled;
77  if (isOn()) {
78  st |= QStyle::Style_On;
79  st |= QStyle::Style_Down;
80  }
81 
82  QRect r(0, 0, height(), width());
83 
84  if (m_position == TabLeft) {
85  p->translate(0, height());
86  p->rotate(-90);
87  }
88  else {
89  p->translate(width(), 0);
90  p->rotate(90);
91  }
92 
93  style().drawControl(QStyle::CE_PushButton, p, this, r, colorGroup(), st);
94  style().drawControl(QStyle::CE_PushButtonLabel, p, this, r, colorGroup(), st);
95 
96  p->restore();
97 }
98 
99 void VTab::setText(const QString &s)
100 {
101  QPushButton::setText(s);
102  const QSize sz = sizeHint();
103  setFixedHeight(sz.height());
104  setFixedWidth(sz.width());
105  updateGeometry();
106 }
107 
108 void VTab::slotToggled(bool b)
109 {
110  emit toggled(m_id,b);
111 }