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

sublime

areaindex.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 "areaindex.h"
00020 
00021 #include <QList>
00022 
00023 #include <kdebug.h>
00024 
00025 #include "view.h"
00026 #include "document.h"
00027 
00028 namespace Sublime {
00029 
00030 // struct AreaIndexPrivate
00031 
00032 struct AreaIndexPrivate {
00033     AreaIndexPrivate()
00034         :parent(0), first(0), second(0), orientation(Qt::Horizontal)
00035     {
00036     }
00037     ~AreaIndexPrivate()
00038     {
00039         delete first;
00040         delete second;
00041     }
00042     AreaIndexPrivate(const AreaIndexPrivate &p)
00043     {
00044         parent = 0;
00045         orientation = p.orientation;
00046         first = p.first ? new AreaIndex(*(p.first)) : 0;
00047         second = p.second ? new AreaIndex(*(p.second)) : 0;
00048     }
00049 
00050     bool isSplitted() const
00051     {
00052         return first || second;
00053     }
00054 
00055     QList<View*> views;
00056 
00057     AreaIndex *parent;
00058     AreaIndex *first;
00059     AreaIndex *second;
00060     Qt::Orientation orientation;
00061 };
00062 
00063 
00064 
00065 // class AreaIndex
00066 
00067 AreaIndex::AreaIndex() : d(new AreaIndexPrivate)
00068 {
00069 }
00070 
00071 AreaIndex::AreaIndex(AreaIndex *parent) : d(new AreaIndexPrivate)
00072 {
00073     d->parent = parent;
00074 }
00075 
00076 AreaIndex::AreaIndex(const AreaIndex &index)  : d(new AreaIndexPrivate( *(index.d) ) )
00077 {
00078     kDebug() << "copying area index";
00079     if (d->first)
00080         d->first->setParent(this);
00081     if (d->second)
00082         d->second->setParent(this);
00083     //clone views in this index
00084     d->views.clear();
00085     foreach (View *view, index.views())
00086         add(view->document()->createView());
00087 }
00088 
00089 AreaIndex::~AreaIndex()
00090 {
00091     delete d;
00092 }
00093 
00094 void AreaIndex::add(View *view, View *after)
00095 {
00096     //we can not add views to the areas that have already been splitted
00097     if (d->isSplitted())
00098         return;
00099 
00100     if (after)
00101         d->views.insert(d->views.indexOf(after), view);
00102     else
00103         d->views.append(view);
00104 }
00105 
00106 void AreaIndex::remove(View *view)
00107 {
00108     if (d->isSplitted())
00109         return;
00110 
00111     d->views.removeAll(view);
00112     if (d->parent && (d->views.count() == 0))
00113         d->parent->unsplit(this);
00114 }
00115 
00116 void Sublime::AreaIndex::split(Qt::Orientation orientation)
00117 {
00118     //we can not split areas that have already been splitted
00119     if (d->isSplitted())
00120         return;
00121 
00122     d->first = new AreaIndex(this);
00123     d->second = new AreaIndex(this);
00124     d->orientation = orientation;
00125 
00126     //assign current views to the first part of splitter
00127     copyTo(d->first);
00128 }
00129 
00130 void AreaIndex::split(View *newView, Qt::Orientation orientation)
00131 {
00132     split(orientation);
00133 
00134     //make new view as second widget in splitter
00135     d->second->add(newView);
00136 }
00137 
00138 void AreaIndex::unsplit(AreaIndex *childToRemove)
00139 {
00140     if (!d->isSplitted())
00141         return;
00142 
00143     AreaIndex *other = d->first == childToRemove ? d->second : d->first;
00144     other->copyTo(this);
00145     d->orientation = other->orientation();
00146     d->first = 0;
00147     d->second = 0;
00148     other->copyChildrenTo(this);
00149 
00150     delete other;
00151     delete childToRemove;
00152 }
00153 
00154 void AreaIndex::copyChildrenTo(AreaIndex *target)
00155 {
00156     if (!d->first || !d->second)
00157         return;
00158     target->d->first = d->first;
00159     target->d->second = d->second;
00160     target->d->first->setParent(target);
00161     target->d->second->setParent(target);
00162 
00163     d->first = 0;
00164     d->second = 0;
00165 }
00166 
00167 void AreaIndex::copyTo(AreaIndex *target)
00168 {
00169     target->d->views = d->views;
00170     d->views.clear();
00171 }
00172 
00173 QList<View*> &AreaIndex::views() const
00174 {
00175     return d->views;
00176 }
00177 
00178 View *AreaIndex::viewAt(int position) const
00179 {
00180     return d->views.value(position, 0);
00181 }
00182 
00183 int AreaIndex::viewCount() const
00184 {
00185     return d->views.count();
00186 }
00187 
00188 bool AreaIndex::hasView(View *view) const
00189 {
00190     return d->views.contains(view);
00191 }
00192 
00193 AreaIndex *AreaIndex::parent() const
00194 {
00195     return d->parent;
00196 }
00197 
00198 void AreaIndex::setParent(AreaIndex *parent)
00199 {
00200     d->parent = parent;
00201 }
00202 
00203 AreaIndex *AreaIndex::first() const
00204 {
00205     return d->first;
00206 }
00207 
00208 AreaIndex *AreaIndex::second() const
00209 {
00210     return d->second;
00211 }
00212 
00213 Qt::Orientation AreaIndex::orientation() const
00214 {
00215     return d->orientation;
00216 }
00217 
00218 bool Sublime::AreaIndex::isSplitted() const
00219 {
00220     return d->isSplitted();
00221 }
00222 
00223 void Sublime::AreaIndex::setOrientation(Qt::Orientation orientation) const
00224 {
00225     d->orientation = orientation;
00226 }
00227 
00228 // class RootAreaIndex
00229 
00230 RootAreaIndex::RootAreaIndex()
00231     :AreaIndex(), d(0)
00232 {
00233 }
00234 
00235 }

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