Merge me later

This exibits broken behavior / crashes.
Test only if willing to help fix the issues
This commit is contained in:
Tomaz Canabrava
2019-05-16 11:45:12 +02:00
parent d79c1b908f
commit 9ba9727a00
6 changed files with 64 additions and 24 deletions

View File

@@ -2,6 +2,7 @@
#include "TerminalDisplay.h"
#include "SessionController.h"
#include "ViewProperties.h"
#include <KLocalizedString>
#include <QBoxLayout>
@@ -9,33 +10,52 @@
#include <QMenu>
#include <QLabel>
#include <QAction>
#include <KToolBarLabelAction>
#include <QToolButton>
namespace Konsole {
TerminalHeaderBar::TerminalHeaderBar(TerminalDisplay *terminalDisplay, QWidget *parent)
: QToolBar(parent),
m_terminalDisplay(terminalDisplay)
TerminalHeaderBar::TerminalHeaderBar(QWidget *parent)
: QWidget(parent)
{
auto closeAction = new QAction(
QIcon::fromTheme(QStringLiteral("tab-close")),
i18nc("@action:inmenu", "Close terminal"),
this
);
m_closeBtn = new QToolButton();
m_closeBtn->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
m_closeBtn->setToolTip(i18nc("@action:itooltip", "Close terminal"));
m_closeBtn->setText(i18nc("@action:itooltip", "Close terminal"));
m_closeBtn->setObjectName(QStringLiteral("close-terminal-button"));
m_closeBtn->setAutoRaise(true);
closeAction->setObjectName(
QStringLiteral("close-terminal")
);
m_terminalTitle = new QLabel();
addSpacer();
addAction(closeAction);
m_boxLayout = new QBoxLayout(QBoxLayout::LeftToRight);
m_boxLayout->setSpacing(0);
m_boxLayout->setMargin(0);
// Layout Setup
m_boxLayout->addStretch();
m_boxLayout->addWidget(m_terminalTitle);
m_boxLayout->addStretch();
m_boxLayout->addWidget(m_closeBtn);
setLayout(m_boxLayout);
}
void TerminalHeaderBar::addSpacer()
// Hack untill I can detangle the creation of the TerminalViews
void TerminalHeaderBar::finishHeaderSetup(ViewProperties *properties)
{
// Spacer
auto *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
addWidget(spacer);
//TODO: Fix ViewProperties signals.
connect(properties, &Konsole::ViewProperties::titleChanged, this,
[this, properties]{
m_terminalTitle->setText(properties->title());
});
/*
connect(item, &Konsole::ViewProperties::iconChanged, this,
&Konsole::TabbedViewContainer::updateIcon);
connect(item, &Konsole::ViewProperties::activity, this,
&Konsole::TabbedViewContainer::updateActivity);
*/
}
}

View File

@@ -1,25 +1,28 @@
#ifndef TERMINAL_HEADER_BAR_H
#define TERMINAL_HEADER_BAR_H
#include <QToolBar>
#include <QWidget>
class QLabel;
class QToolButton;
class QBoxLayout;
namespace Konsole {
class TerminalDisplay;
class ViewProperties;
class TerminalHeaderBar : public QToolBar {
class TerminalHeaderBar : public QWidget {
Q_OBJECT
public:
// TODO: Verify if the terminalDisplay is needed, or some other thing like SessionController.
TerminalHeaderBar(TerminalDisplay *terminalDisplay, QWidget *parent = nullptr);
TerminalHeaderBar(QWidget *parent = nullptr);
void finishHeaderSetup(ViewProperties *properties);
private:
void addSpacer();
QBoxLayout *m_boxLayout;
TerminalDisplay *m_terminalDisplay;
QLabel *m_terminalTitle;
std::vector<QAction*> m_actions;
QToolButton *m_closeBtn;
};
} // namespace Konsole

View File

@@ -2,6 +2,8 @@
#include "TerminalHeaderBar.h"
#include "TerminalDisplay.h"
#include "ViewProperties.h"
#include "SessionController.h"
#include <QBoxLayout>
@@ -22,6 +24,11 @@ TerminalWidget::TerminalWidget(uint randomSeed, QWidget *parent)
setLayout(internalLayout);
}
void TerminalWidget::finishTerminalSetup()
{
m_headerBar->finishHeaderSetup(m_terminalDisplay->sessionController());
}
TerminalDisplay *TerminalWidget::terminalDisplay() const {
return m_terminalDisplay;
}

View File

@@ -14,10 +14,13 @@ namespace Konsole {
TerminalWidget(uint randomSeed, QWidget *parent = nullptr);
TerminalHeaderBar *headerBar() const;
TerminalDisplay *terminalDisplay() const;
// Hack untill I can detangle the setup of the TerminalViews.
void finishTerminalSetup();
private:
TerminalHeaderBar *m_headerBar;
TerminalDisplay *m_terminalDisplay;
};
};
}
#endif

View File

@@ -310,6 +310,7 @@ void TabbedViewContainer::splitView(TerminalWidget *widget, Qt::Orientation orie
connectTerminalDisplay(widget->terminalDisplay());
}
//TODO: Those two functions below can be templated pure functions so I can reuse in different classes.
void TabbedViewContainer::connectTerminalDisplay(TerminalDisplay *display)
{
auto item = display->sessionController();

View File

@@ -574,6 +574,7 @@ void ViewManager::shrinkActiveContainer()
_viewContainer->activeViewSplitter()->adjustActiveTerminalDisplaySize(-10);
}
//TODO: Those connects should be done by the Controller Constructor
SessionController *ViewManager::createController(Session *session, TerminalDisplay *view)
{
// create a new controller for the session, and ensure that this view manager
@@ -636,6 +637,9 @@ void ViewManager::attachView(TerminalDisplay *terminal, Session *session)
_terminalDisplayHistory.append(terminal);
}
/* TODO: This function should migrate to the Constructor of the TerminalDisplay
* or at least to the constructor of TerminalWidget / TerminalDisplay
*/
TerminalWidget *ViewManager::createView(Session *session)
{
// notify this view manager when the session finishes so that its view
@@ -666,6 +670,8 @@ TerminalWidget *ViewManager::createView(Session *session)
display->setFocus(Qt::OtherFocusReason);
// updateDetachViewState();
// HACK, The setup above should be inside TerminalDisplay constructor.
terminalWidget->finishTerminalSetup();
return terminalWidget;
}