• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/App

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • App
  • Ui
TabWidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2008-2010 Tomaz Canabrava <tomaz.canabrava@gmail.com>
4  Copyright 2008 Ugo Sangiori <ugorox@gmail.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "TabWidget.h"
21 #include <QBoxLayout>
22 #include <QStackedWidget>
23 
24 #include <kmultitabbar.h>
25 #include <KIcon>
26 #include <KDebug>
27 #include <KAction>
28 #include <KLocale>
29 
30 TabWidget::TabWidget(TabWidget::Orientation o, QWidget *parent) : QWidget(parent)
31 {
32  m_orientation = o;
33  m_layout = 0;
34  m_numOfTabs = 0;
35  m_tabs = new KMultiTabBar((KMultiTabBar::KMultiTabBarPosition)o, this);
36  m_tabs->setStyle(KMultiTabBar::KDEV3ICON);
37  m_widgets = new QStackedWidget(this);
38  createLayout();
39 }
40 
41 void TabWidget::createLayout()
42 {
43  delete m_layout;
44  if ((m_orientation == TabOnLeft) || (m_orientation == TabOnRight)) {
45  m_layout = new QBoxLayout(QBoxLayout::LeftToRight, this);
46  } else {
47  m_layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
48  }
49  m_layout->setSizeConstraint(QLayout::SetMaximumSize);
50  switch (m_orientation) {
51  case TabOnLeft :
52  case TabOnTop:
53  m_layout->addWidget(m_tabs);
54  m_layout->addWidget(m_widgets);
55  break;
56  case TabOnRight :
57  case TabOnBottom:
58  m_layout->addWidget(m_widgets);
59  m_layout->addWidget(m_tabs);
60  break;
61  }
62 }
63 
64 void TabWidget::controlPanel(int index)
65 {
66  if (m_widgets -> currentIndex() == index) {
67  m_widgets ->setVisible(! m_widgets -> isVisible());
68  } else {
69  m_widgets->setCurrentIndex(index);
70  releaseButton(index);
71  emit widgetActivated(index);
72  }
73  kDebug() << "Widget Size: " << size();
74 }
75 
76 void TabWidget::releaseButton(int index)
77 {
78  if (m_activeTab == index) {
79  m_tabs -> setTab(m_activeTab, true);
80  return;
81  }
82  m_tabs -> setTab(m_activeTab, false);
83  m_activeTab = index;
84 }
85 
86 void TabWidget::addWidget(QWidget *w, const QString& text, const KIcon& icon)
87 {
88  m_widgets -> addWidget(w);
89  m_tabs -> appendTab(icon.pixmap(16), m_numOfTabs, text);
90 
91  if (m_numOfTabs == 0) {
92  m_tabs->setTab(m_numOfTabs, true);
93  }
94 
95  connect(m_tabs->tab(m_numOfTabs), SIGNAL(clicked(int)), this, SLOT(controlPanel(int)));
96  m_numOfTabs++;
97 }
98 
99 void TabWidget::addAction(KAction *a)
100 {
101  int pos = m_numOfTabs + m_numOfActions;
102  m_tabs -> appendTab(a->icon().pixmap(16), pos, a->text());
103  m_tabs -> addAction(a);
104  connect(m_tabs->tab(pos), SIGNAL(clicked(int)), a, SLOT(trigger()));
105  connect(m_tabs->tab(pos), SIGNAL(clicked(int)), this, SLOT(releaseActionButton(int)));
106  _runAction = a;
107 
108 }
109 
110 void TabWidget::releaseActionButton(int index)
111 {
112  m_tabs->setTab(m_activeTab, true);
113  m_tabs->setTab(index, false);
114 }
QWidget
TabWidget::TabOnLeft
Definition: TabWidget.h:37
TabWidget::addAction
void addAction(KAction *a)
Definition: TabWidget.cpp:99
TabWidget::TabOnBottom
Definition: TabWidget.h:37
QLayout::setSizeConstraint
void setSizeConstraint(SizeConstraint)
QWidget::setVisible
virtual void setVisible(bool visible)
TabWidget::widgetActivated
void widgetActivated(int id)
QWidget::size
QSize size() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
TabWidget::TabOnTop
Definition: TabWidget.h:37
TabWidget::Orientation
Orientation
Definition: TabWidget.h:37
QStackedWidget::setCurrentIndex
void setCurrentIndex(int index)
QWidget::pos
QPoint pos() const
QStackedWidget
QString
TabWidget::addWidget
void addWidget(QWidget *w, const QString &text, const KIcon &icon)
Definition: TabWidget.cpp:86
TabWidget::TabWidget
TabWidget(TabWidget::Orientation o, QWidget *parent=0)
Definition: TabWidget.cpp:30
TabWidget.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QBoxLayout
TabWidget::TabOnRight
Definition: TabWidget.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/App

Skip menu "rocs/App"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal