-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vertical and horizontal splits (#38)
- Loading branch information
Showing
11 changed files
with
251 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "container.hpp" | ||
#include "kakounewidget.hpp" | ||
#include <qnamespace.h> | ||
#include <qwidget.h> | ||
|
||
Container::Container(Qt::Orientation orientation, QWidget *parent) : QWidget(parent) | ||
{ | ||
QHBoxLayout *layout = new QHBoxLayout(this); | ||
layout->setContentsMargins(0, 0, 0, 0); | ||
|
||
m_splitter = new QSplitter(this); | ||
m_splitter->setOrientation(orientation); | ||
|
||
layout->addWidget(m_splitter); | ||
} | ||
|
||
void Container::addWidget(QWidget *widget) | ||
{ | ||
connectWidget(widget); | ||
m_splitter->addWidget(widget); | ||
} | ||
|
||
Qt::Orientation Container::getOrientation() const | ||
{ | ||
return m_splitter->orientation(); | ||
} | ||
|
||
void Container::connectWidget(QWidget *widget) | ||
{ | ||
if (KakouneWidget *kak_widget = qobject_cast<KakouneWidget *>(widget)) | ||
connectKakouneWidget(kak_widget); | ||
|
||
connect(widget, &QWidget::destroyed, this, [=]() { | ||
if (m_splitter->count() == 0) | ||
{ | ||
deleteLater(); | ||
} | ||
else | ||
{ | ||
m_splitter->widget(0)->setFocus(); | ||
} | ||
}); | ||
} | ||
|
||
void Container::connectKakouneWidget(KakouneWidget *kak_widget) | ||
{ | ||
connect(kak_widget, &KakouneWidget::finished, this, [=]() { | ||
kak_widget->setParent(nullptr); | ||
kak_widget->deleteLater(); | ||
}); | ||
} | ||
|
||
void Container::focusInEvent(QFocusEvent *event) | ||
{ | ||
m_splitter->widget(0)->setFocus(); | ||
} | ||
|
||
Container *Container::findParentContainer(QWidget *widget) | ||
{ | ||
QWidget *parent_container = widget->parentWidget(); | ||
while (parent_container) | ||
{ | ||
Container *container = qobject_cast<Container *>(parent_container); | ||
if (container) | ||
{ | ||
return container; | ||
} | ||
parent_container = parent_container->parentWidget(); | ||
} | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef CONTAINER_HPP | ||
#define CONTAINER_HPP | ||
|
||
#include "kakounewidget.hpp" | ||
#include <qnamespace.h> | ||
#include <qtmetamacros.h> | ||
#include <qvariant.h> | ||
#include <qwidget.h> | ||
|
||
class Container : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
Container(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = nullptr); | ||
|
||
void addWidget(QWidget *widget); | ||
|
||
Qt::Orientation getOrientation() const; | ||
|
||
static Container *findParentContainer(QWidget *widget); | ||
|
||
protected: | ||
void connectWidget(QWidget *widget); | ||
void connectKakouneWidget(KakouneWidget *kak_widget); | ||
|
||
void focusInEvent(QFocusEvent *event) override; | ||
|
||
QSplitter *m_splitter; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.