~mrp/aerodramus

1ec09b77ab1117940a99e25883bff5b38a4333f2 — Mark Penner 6 months ago ee22878
add rudimentary page list
2 files changed, 28 insertions(+), 4 deletions(-)

M src/MainWindow.cpp
M src/MainWindow.h
M src/MainWindow.cpp => src/MainWindow.cpp +21 -3
@@ 8,13 8,23 @@
#include <KStandardAction>
#include <QAction>
#include <QApplication>
#include <QDockWidget>
#include <QFileDialog>
#include <QLabel>
#include <QStandardPaths>

MainWindow::MainWindow(QWidget *parent)
    : KXmlGuiWindow(parent)
    , m_pageStack{new QStackedWidget}
    , m_pageList{new QListWidget}
{
    centralWidget = new QWidget();
    setCentralWidget(centralWidget);
    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);

    setupActions();
    setupGUI(Default, QStringLiteral("aerodramusui.rc"));


@@ 31,5 41,13 @@ void MainWindow::openFile()
    const QString fileNameFromDialog =
        QFileDialog::getOpenFileName(this, i18n("Open File"), QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);

    qDebug() << "opening " << fileNameFromDialog;
    QLabel *page = new QLabel(fileNameFromDialog);
    addPage(fileNameFromDialog, 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);
}

M src/MainWindow.h => src/MainWindow.h +7 -1
@@ 5,6 5,9 @@
#define MAINWINDOW_H

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

class MainWindow : public KXmlGuiWindow
{


@@ 13,11 16,14 @@ public:
    explicit MainWindow(QWidget *parent = nullptr);

private:
    QWidget *centralWidget;
    QStackedWidget *m_pageStack;
    QListWidget *m_pageList;

    void setupActions();

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

#endif // MAINWINDOW_H