~mrp/aerodramus

49ad2d22bcad6cf789d494864fa4a7832716160d — Mark Penner 4 months ago aea4a02
use KPageWidget
4 files changed, 14 insertions(+), 41 deletions(-)

M CMakeLists.txt
M src/CMakeLists.txt
M src/MainWindow.cpp
M src/MainWindow.h
M CMakeLists.txt => CMakeLists.txt +1 -0
@@ 34,6 34,7 @@ find_package(Qt6 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS
find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS
    I18n
    CoreAddons
    WidgetsAddons
    XmlGui
)


M src/CMakeLists.txt => src/CMakeLists.txt +1 -0
@@ 21,6 21,7 @@ target_link_libraries(aerodramus-gui PRIVATE
    Qt::Widgets
    KF6::I18n
    KF6::CoreAddons
    KF6::WidgetsAddons
    KF6::XmlGui
)
set_target_properties(aerodramus-gui PROPERTIES OUTPUT_NAME "aerodramus")

M src/MainWindow.cpp => src/MainWindow.cpp +10 -34
@@ 17,16 17,9 @@ using namespace Qt::Literals::StringLiterals;

MainWindow::MainWindow(QWidget *parent)
    : KXmlGuiWindow(parent)
    , m_pageStack{new QStackedWidget}
    , m_pageList{new QListWidget}
    , m_pageWidget{new KPageWidget}
{
    QDockWidget *pageDock = new QDockWidget(i18n("Pages"), this, Qt::WindowFlags());
    pageDock->setFeatures(QDockWidget::DockWidgetMovable);
    pageDock->setWidget(m_pageList);
    this->addDockWidget(Qt::LeftDockWidgetArea, pageDock);

    setCentralWidget(m_pageStack);
    connect(m_pageList, &QListWidget::currentRowChanged, m_pageStack, &QStackedWidget::setCurrentIndex);
    setCentralWidget(m_pageWidget);

    setupActions();
    setupGUI(Default, u"aerodramusui.rc"_s);


@@ 39,11 32,16 @@ void MainWindow::setupActions()

    QAction *addCalcPageAction = new QAction(QIcon::fromTheme(u"accessories-calculator"_s), i18n("&Add Calculator"), this);
    actionCollection()->addAction(u"addCalcPage"_s, addCalcPageAction);
    connect(addCalcPageAction, &QAction::triggered, this, &MainWindow::addCalcPage);
    connect(addCalcPageAction, &QAction::triggered, this, [this]() {
        CalculatorPage *page = new CalculatorPage(nullptr, this);
        m_pageWidget->addPage(page, i18n("Calculator"));
    });

    QAction *closeCurrentPageAction = new QAction(QIcon::fromTheme(u"window-close"_s), i18n("&Close Page"), this);
    actionCollection()->addAction(u"closeCurrentPage"_s, closeCurrentPageAction);
    connect(closeCurrentPageAction, &QAction::triggered, this, &MainWindow::closeCurrentPage);
    connect(closeCurrentPageAction, &QAction::triggered, this, [this]() {
        m_pageWidget->removePage(m_pageWidget->currentPage());
    });
}

void MainWindow::openFile()


@@ 52,27 50,5 @@ void MainWindow::openFile()
        QFileDialog::getOpenFileName(this, i18n("Open File"), QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);

    ImpulseResponsePage *page = new ImpulseResponsePage(fileNameFromDialog, this);
    addPage(fileNameFromDialog, page);
}

void MainWindow::addCalcPage()
{
    CalculatorPage *page = new CalculatorPage(nullptr, this);
    addPage(i18n("Calculator"), page);
}

void MainWindow::addPage(const QString &title, QWidget *widget)
{
    m_pageStack->addWidget(widget);
    m_pageList->addItem(title);
    m_pageList->setCurrentRow(m_pageList->count() - 1, QItemSelectionModel::ClearAndSelect);
}

void MainWindow::closeCurrentPage()
{
    QWidget *page = m_pageStack->currentWidget();
    int row = m_pageList->currentIndex().row();
    delete m_pageList->takeItem(row);
    m_pageStack->removeWidget(page);
    delete page;
    m_pageWidget->addPage(page, fileNameFromDialog);
}

M src/MainWindow.h => src/MainWindow.h +2 -7
@@ 4,9 4,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <KPageWidget>
#include <KXmlGuiWindow>
#include <QListWidget>
#include <QStackedWidget>
#include <QWidget>

class MainWindow : public KXmlGuiWindow


@@ 16,16 15,12 @@ public:
    explicit MainWindow(QWidget *parent = nullptr);

private:
    QStackedWidget *m_pageStack;
    QListWidget *m_pageList;
    KPageWidget *m_pageWidget;

    void setupActions();

private Q_SLOTS:
    void openFile();
    void addPage(const QString &title, QWidget *widget);
    void addCalcPage();
    void closeCurrentPage();
};

#endif // MAINWINDOW_H