File indexing completed on 2024-05-19 04:39:50

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Alexander Dymo <adymo@kdevelop.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "areaprinter.h"
0008 
0009 #include <sublime/view.h>
0010 #include <sublime/areaindex.h>
0011 
0012 using namespace Sublime;
0013 
0014 // class AreaViewsPrinter
0015 
0016 AreaViewsPrinter::AreaViewsPrinter()
0017 {
0018     result = QStringLiteral("\n");
0019 }
0020 
0021 Area::WalkerMode AreaViewsPrinter::operator()(Sublime::AreaIndex *index)
0022 {
0023     result += printIndentation(index) + "[ ";
0024     if (index->views().isEmpty())
0025         result += printOrientation(index->orientation()) + ' ';
0026     else
0027     {
0028         for (View* view : qAsConst(index->views())) {
0029             result += view->objectName() + ' ';
0030         }
0031     }
0032     result += QLatin1String("]\n");
0033     return Area::ContinueWalker;
0034 }
0035 
0036 QString AreaViewsPrinter::printIndentation(Sublime::AreaIndex *index) const
0037 {
0038     QString i;
0039     while ((index = index->parent()))
0040         i += QLatin1String("    ");
0041     return i;
0042 }
0043 
0044 QString AreaViewsPrinter::printOrientation(Qt::Orientation o) const
0045 {
0046     if (o == Qt::Vertical)
0047         return QStringLiteral("vertical splitter");
0048     else
0049         return QStringLiteral("horizontal splitter");
0050 }
0051 
0052 
0053 
0054 // class AreaToolViewsPrinter
0055 
0056 AreaToolViewsPrinter::AreaToolViewsPrinter()
0057 {
0058     result = QStringLiteral("\n");
0059 }
0060 
0061 Area::WalkerMode AreaToolViewsPrinter::operator()(Sublime::View *view, Sublime::Position position)
0062 {
0063     result += view->objectName() + " [ " + printPosition(position) + " ]" + '\n';
0064     return Area::ContinueWalker;
0065 }
0066 
0067 QString AreaToolViewsPrinter::printPosition(Sublime::Position position)
0068 {
0069     switch (position)
0070     {
0071         case Sublime::Left: return QStringLiteral("left");
0072         case Sublime::Right: return QStringLiteral("right");
0073         case Sublime::Bottom: return QStringLiteral("bottom");
0074         case Sublime::Top: return QStringLiteral("top");
0075         default: return QStringLiteral("wrong position");
0076     }
0077 }
0078