File: MainWindow.cpp

package info (click to toggle)
qt-advanced-docking-system 3.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 13,600 kB
  • sloc: cpp: 11,678; python: 2,623; makefile: 12
file content (78 lines) | stat: -rw-r--r-- 2,311 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "../../examples/hideshow/MainWindow.h"

#include "ui_MainWindow.h"

#include <QLabel>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->centralWidget->setLayout( m_layout = new QStackedLayout() );

    m_welcomeWidget = new QWidget(this);
    auto welcomeLayout = new QVBoxLayout(m_welcomeWidget);
    welcomeLayout->addStretch();
    QPushButton* openButton = new QPushButton("Open project");
    welcomeLayout->addWidget( openButton );
    welcomeLayout->addStretch();

    connect( openButton, SIGNAL(clicked()), this, SLOT(openProject()) );

    m_DockManager = new ads::CDockManager(ui->centralWidget);

    // Create example content label - this can be any application specific
	// widget
	QLabel* l = new QLabel();
	l->setWordWrap(true);
	l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
	l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");

	// Create a dock widget with the title Label 1 and set the created label
	// as the dock widget content
	ads::CDockWidget* DockWidget = new ads::CDockWidget("Label 1");
	DockWidget->setWidget(l);

	// Add the toggleViewAction of the dock widget to the menu to give
	// the user the possibility to show the dock widget if it has been closed
	ui->menuView->addAction(DockWidget->toggleViewAction());

    connect( ui->actionOpen, SIGNAL(triggered()), this, SLOT(openProject()) );
    connect( ui->actionClose, SIGNAL(triggered()), this, SLOT(closeProject()) );

	// Add the dock widget to the top dock widget area
	m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);

    ui->centralWidget->layout()->addWidget( m_welcomeWidget );
    ui->centralWidget->layout()->addWidget( m_DockManager );

    closeProject();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::openProject()
{
    ui->actionOpen->setEnabled(false);
    ui->actionClose->setEnabled(true);
    ui->menuView->setEnabled(true);

    m_layout->setCurrentWidget( m_DockManager );
}

void MainWindow::closeProject()
{
    ui->actionOpen->setEnabled(true);
    ui->actionClose->setEnabled(false);
    ui->menuView->setEnabled(false);

    m_DockManager->hideManagerAndFloatingWidgets();
    m_layout->setCurrentWidget( m_welcomeWidget );
}