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

0001 /*
0002     SPDX-FileCopyrightText: 2007 Alexander Dymo <adymo@kdevelop.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "example2main.h"
0008 
0009 #include <QMenu>
0010 
0011 #include <QMenuBar>
0012 
0013 #include <sublime/area.h>
0014 #include <sublime/view.h>
0015 #include <sublime/document.h>
0016 
0017 Example2Main::Example2Main(Sublime::Controller *controller, Qt::WindowFlags flags)
0018     :Sublime::MainWindow(controller, flags)
0019 {
0020     auto* windowMenu = new QMenu(QStringLiteral("Window"), this);
0021     windowMenu->addAction(QStringLiteral("Split Top/Bottom"), this, SLOT(splitVertical()), Qt::CTRL | Qt::Key_T);
0022     windowMenu->addAction(QStringLiteral("Split Left/Right"), this, SLOT(splitHorizontal()), Qt::CTRL | Qt::Key_L);
0023     windowMenu->addSeparator();
0024     windowMenu->addAction(QStringLiteral("Close"), this, SLOT(close()), Qt::CTRL | Qt::Key_W);
0025     menuBar()->addMenu(windowMenu);
0026 }
0027 
0028 void Example2Main::splitVertical()
0029 {
0030     if (!activeView())
0031         return;
0032     Sublime::View *newView = activeView()->document()->createView();
0033     area()->addView(newView, activeView(), Qt::Vertical);
0034     activateView(newView);
0035 }
0036 
0037 void Example2Main::splitHorizontal()
0038 {
0039     if (!activeView())
0040         return;
0041     Sublime::View *newView = activeView()->document()->createView();
0042     area()->addView(newView, activeView(), Qt::Horizontal);
0043     activateView(newView);
0044 }
0045 
0046 void Example2Main::close()
0047 {
0048     if (!activeView() || area()->views().count() == 1)
0049         return;
0050     delete area()->removeView(activeView());
0051 }
0052 
0053 #include "moc_example2main.cpp"