Use a QTabWidget for the different modes in DebugConsole

Summary: Replaces the custom logic to switch between the three modes by tabs.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1271
This commit is contained in:
Martin Gräßlin 2016-03-31 09:19:35 +02:00
parent 3edf5a7b0a
commit 90b9b08d7a
2 changed files with 55 additions and 91 deletions

View file

@ -309,62 +309,29 @@ DebugConsole::DebugConsole()
, m_ui(new Ui::DebugConsole)
{
m_ui->setupUi(this);
m_ui->treeView->setItemDelegate(new DebugConsoleDelegate(this));
m_ui->treeView->setModel(new DebugConsoleModel(this));
m_ui->windowsView->setItemDelegate(new DebugConsoleDelegate(this));
m_ui->windowsView->setModel(new DebugConsoleModel(this));
m_ui->surfacesView->setModel(new SurfaceTreeModel(this));
m_ui->quitButton->setIcon(QIcon::fromTheme(QStringLiteral("application-exit")));
m_ui->windowsButton->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
m_ui->surfacesButton->setIcon(QIcon::fromTheme(QStringLiteral("view-list-tree")));
m_ui->tabWidget->setTabIcon(0, QIcon::fromTheme(QStringLiteral("view-list-tree")));
m_ui->tabWidget->setTabIcon(1, QIcon::fromTheme(QStringLiteral("view-list-tree")));
if (kwinApp()->operationMode() == Application::OperationMode::OperationModeX11) {
m_ui->surfacesButton->setDisabled(true);
m_ui->inputEventsButton->setDisabled(true);
m_ui->tabWidget->setTabEnabled(1, false);
m_ui->tabWidget->setTabEnabled(2, false);
}
connect(m_ui->quitButton, &QAbstractButton::clicked, this, &DebugConsole::deleteLater);
connect(m_ui->windowsButton, &QAbstractButton::toggled, this,
[this] (bool toggled) {
if (!toggled) {
return;
}
m_ui->surfacesButton->setChecked(false);
m_ui->inputEventsButton->setChecked(false);
m_ui->treeView->model()->deleteLater();
m_ui->treeView->setModel(new DebugConsoleModel(this));
m_ui->treeView->setVisible(true);
m_ui->inputTextEdit->setVisible(false);
}
);
connect(m_ui->surfacesButton, &QAbstractButton::toggled, this,
[this] (bool toggled) {
if (!toggled) {
return;
}
m_ui->windowsButton->setChecked(false);
m_ui->inputEventsButton->setChecked(false);
m_ui->treeView->model()->deleteLater();
m_ui->treeView->setModel(new SurfaceTreeModel(this));
m_ui->treeView->setVisible(true);
m_ui->inputTextEdit->setVisible(false);
}
);
connect(m_ui->inputEventsButton, &QAbstractButton::toggled, this,
[this] (bool toggled) {
if (!toggled) {
return;
}
m_ui->windowsButton->setChecked(false);
m_ui->surfacesButton->setChecked(false);
m_ui->treeView->setVisible(false);
m_ui->inputTextEdit->setVisible(true);
if (m_inputFilter.isNull()) {
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this,
[this] (int index) {
// delay creation of input event filter until the tab is selected
if (index == 2 && m_inputFilter.isNull()) {
m_inputFilter.reset(new DebugConsoleFilter(m_ui->inputTextEdit));
input()->prepandInputEventFilter(m_inputFilter.data());
}
}
);
m_ui->inputTextEdit->setVisible(false);
// for X11
setWindowFlags(Qt::X11BypassWindowManagerHint);
}

View file

@ -16,39 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="windowsButton">
<property name="text">
<string>Windows</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="surfacesButton">
<property name="text">
<string>Surfaces</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="inputEventsButton">
<property name="text">
<string>Input Events</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -72,27 +39,57 @@
</layout>
</item>
<item>
<widget class="QTreeView" name="treeView">
<attribute name="headerDefaultSectionSize">
<number>250</number>
</attribute>
</widget>
</item>
<item>
<widget class="QTextEdit" name="inputTextEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="windows">
<attribute name="title">
<string>Windows</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTreeView" name="windowsView">
<attribute name="headerDefaultSectionSize">
<number>250</number>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="surfaces">
<attribute name="title">
<string>Surfaces</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTreeView" name="surfacesView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="input">
<attribute name="title">
<string>Input Events</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTextEdit" name="inputTextEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>quitButton</tabstop>
<tabstop>treeView</tabstop>
</tabstops>
<resources/>
<connections/>