• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

sublime

container.cpp

00001 /***************************************************************************
00002  *   Copyright 2006-2007 Alexander Dymo  <adymo@kdevelop.org>              *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU Library General Public License as       *
00006  *   published by the Free Software Foundation; either version 2 of the    *
00007  *   License, or (at your option) any later version.                       *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Library General Public     *
00015  *   License along with this program; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
00018  ***************************************************************************/
00019 #include "container.h"
00020 
00021 #include <QMap>
00022 #include <QLayout>
00023 #include <QTabBar>
00024 #include <QStackedLayout>
00025 
00026 #include <kconfig.h>
00027 #include <kconfiggroup.h>
00028 #include <ksharedconfig.h>
00029 #include <kglobal.h>
00030 #include <kacceleratormanager.h>
00031 
00032 #include "view.h"
00033 #include "document.h"
00034 #include "containerstyle.h"
00035 
00036 namespace Sublime {
00037 
00038 // struct ContainerPrivate
00039 
00040 struct ContainerPrivate {
00041     QMap<QWidget*, View*> viewForWidget;
00042 };
00043 
00044 
00045 
00046 // class Container
00047 
00048 Container::Container(QWidget *parent)
00049     :KTabWidget(parent), d(new ContainerPrivate())
00050 {
00051     KAcceleratorManager::setNoAccel(this);
00052 
00053     // Set the widget style to a forwarding proxy style that removes the tabwidget frame,
00054     // and draws a tabbar base underneath the tabbar.
00055     setStyle(new ContainerStyle(this));
00056     // The base will be drawn on the frame instead of on the tabbar, so it extends across
00057     // the whole widget.
00058     tabBar()->setDrawBase(false);
00059 
00060     KConfigGroup group = KGlobal::config()->group("UiSettings");
00061     setTabBarHidden(group.readEntry("TabBarVisibility", 1) == 0);
00062     setHoverCloseButton(true);
00063     setCloseButtonEnabled(true);
00064     connect(this, SIGNAL(currentChanged(int)), this, SLOT(widgetActivated(int)));
00065 }
00066 
00067 Container::~Container()
00068 {
00069     delete d;
00070 }
00071 
00072 void Container::widgetActivated(int idx)
00073 {
00074     if (idx < 0)
00075         return;
00076     if (QWidget* w = widget(idx)) {
00077         w->setFocus();
00078         if(d->viewForWidget.contains(w))
00079             emit activateView(d->viewForWidget[w]);
00080     }
00081 }
00082 
00083 void Container::addWidget(View *view)
00084 {
00085     QWidget *w = view->widget(this);
00086     addTab(w, view->document()->title());
00087     d->viewForWidget[w] = view;
00088     connect(view->document(), SIGNAL(titleChanged(Sublime::Document*)), this, SLOT(documentTitleChanged(Sublime::Document*)));
00089 }
00090 
00091 void Container::documentTitleChanged(Sublime::Document* doc)
00092 {
00093     QMapIterator<QWidget*, View*> it = d->viewForWidget;
00094     while (it.hasNext()) {
00095         if (it.next().value()->document() == doc) {
00096             int tabIndex = indexOf(it.key());
00097             if (tabIndex != -1) {
00098                 setTabText(tabIndex, doc->title());
00099             }
00100             break;
00101         }
00102     }
00103 }
00104 
00105 void Sublime::Container::removeWidget(QWidget *w)
00106 {
00107     if (w) {
00108         removeTab(indexOf(w));
00109         View* view = d->viewForWidget.take(w);
00110         disconnect(view->document(), SIGNAL(titleChanged(Sublime::Document*)), this, SLOT(documentTitleChanged(Sublime::Document*)));
00111     }
00112 }
00113 
00114 bool Container::hasWidget(QWidget *w)
00115 {
00116     return indexOf(w) != -1;
00117 }
00118 
00119 View *Container::viewForWidget(QWidget *w) const
00120 {
00121     return d->viewForWidget[w];
00122 }
00123 
00124 void Container::paintEvent(QPaintEvent *ev)
00125 {
00126     //paint ourselves only if tabbar is visible
00127     if (tabBar()->isVisible())
00128         KTabWidget::paintEvent(ev);
00129     //otherwise don't paint anything (especially the border around the widget)
00130 }
00131 
00132 void Container::setTabBarHidden(bool hide)
00133 {
00134     KTabWidget::setTabBarHidden(hide);
00135 }
00136 
00137 }
00138 
00139 #include "container.moc"
00140 

sublime

Skip menu "sublime"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  •     interfaces
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal