Commit bb637025 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Show button only when mouse is in treeview

parent 9c5fd3db
Pipeline #250984 failed with stage
in 5 minutes
......@@ -12,35 +12,16 @@
#include <KSyntaxHighlighting/Theme>
#include <KTextEditor/Editor>
#include <QPushButton>
Results::Results(QWidget *parent)
: QWidget(parent)
, m_detachButton(new QPushButton(this))
{
setupUi(this);
m_detachButton->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow")));
m_detachButton->show();
m_detachButton->raise();
m_detachButton->resize(m_detachButton->minimumSizeHint());
connect(m_detachButton, &QAbstractButton::clicked, this, [this] {
m_detachButton->setEnabled(false);
m_detachButton->setVisible(false);
treeView->setItemDelegate(new SearchResultsDelegate(treeView));
connect(treeView, &ResultsTreeView::detachClicked, this, [this] {
Q_EMIT requestDetachToMainWindow(this);
});
connect(treeView, &ResultsTreeView::geometryChanged, this, [this] {
auto topRight = treeView->viewport()->geometry().topRight();
topRight.rx() -= 4;
topRight.ry() += 4;
auto btnGeometry = m_detachButton->geometry();
btnGeometry.moveTopRight(topRight);
m_detachButton->setGeometry(btnGeometry);
});
treeView->setItemDelegate(new SearchResultsDelegate(treeView));
MatchProxyModel *proxy = new MatchProxyModel(this);
proxy->setSourceModel(&matchModel);
proxy->setRecursiveFilteringEnabled(true);
......
......@@ -27,7 +27,7 @@ public:
QString treeRootText;
MatchModel matchModel;
bool displayFolderOptions = false;
class QPushButton *const m_detachButton;
bool isDetachedToMainWindow = false;
// Used by katemainwindow when we try to close this widget
Q_INVOKABLE bool shouldClose()
......
......@@ -6,11 +6,16 @@
*/
#include "ResultsTreeView.h"
#include "Results.h"
#include <QPushButton>
#include <KSyntaxHighlighting/Theme>
#include <KTextEditor/Editor>
ResultsTreeView::ResultsTreeView(QWidget *parent)
: QTreeView(parent)
, m_detachButton(new QPushButton(this))
{
auto updateColors = [this](KTextEditor::Editor *e) {
if (!e) {
......@@ -29,6 +34,24 @@ ResultsTreeView::ResultsTreeView(QWidget *parent)
setPalette(pal);
};
connect(this, &ResultsTreeView::geometryChanged, this, [this] {
auto topRight = viewport()->geometry().topRight();
topRight.rx() -= 4;
topRight.ry() += 4;
auto btnGeometry = m_detachButton->geometry();
btnGeometry.moveTopRight(topRight);
m_detachButton->setGeometry(btnGeometry);
});
m_detachButton->setIcon(QIcon::fromTheme(QStringLiteral("draw-arrow")));
m_detachButton->resize(m_detachButton->minimumSizeHint());
connect(m_detachButton, &QAbstractButton::clicked, this, [this] {
m_detachButton->setEnabled(false);
m_detachButton->setVisible(false);
Q_EMIT detachClicked();
});
m_detachButton->setVisible(false);
auto *e = KTextEditor::Editor::instance();
connect(e, &KTextEditor::Editor::configChanged, this, updateColors);
updateColors(e);
......@@ -60,3 +83,21 @@ void ResultsTreeView::resizeEvent(QResizeEvent *e)
Q_EMIT geometryChanged();
QTreeView::resizeEvent(e);
}
void ResultsTreeView::enterEvent(QEvent *e)
{
auto *res = qobject_cast<Results *>(parent());
if (!res) {
qWarning() << Q_FUNC_INFO << "Unexpected null parent() Results";
QTreeView::enterEvent(e);
return;
}
m_detachButton->setVisible(!res->isEmpty() && !res->isDetachedToMainWindow);
QTreeView::enterEvent(e);
}
void ResultsTreeView::leaveEvent(QEvent *e)
{
m_detachButton->hide();
QTreeView::leaveEvent(e);
}
......@@ -23,12 +23,16 @@ public:
private:
QColor m_fg;
class QPushButton *const m_detachButton;
protected:
void resizeEvent(QResizeEvent *) override;
void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override;
Q_SIGNALS:
void geometryChanged();
void detachClicked();
};
#endif
......@@ -2027,7 +2027,10 @@ void KatePluginSearchView::detachTabToMainWindow(Results *res)
res->setWindowIcon(QIcon::fromTheme(QStringLiteral("edit-find")));
res->setWindowTitle(i18n("Search: %1", m_tabBar->tabText(i)));
Utils::addWidget(res, m_mainWindow);
res = nullptr;
if (res == m_curResults) {
m_curResults = nullptr;
}
res->isDetachedToMainWindow = true;
m_tabBar->removeTab(i);
addTab();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment