Commit c2594aa3 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts

search: make item margin configurable

... to support more or less compact presentation as preferred
parent f96e8e5a
......@@ -39,7 +39,7 @@ void SPHtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
initStyleOption(&options, index);
QTextDocument doc;
//doc.setDocumentMargin(0);
doc.setDocumentMargin(m_itemMargin);
doc.setHtml(index.data().toString());
painter->save();
......@@ -67,7 +67,7 @@ void SPHtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
QSize SPHtmlDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& index) const
{
QTextDocument doc;
//doc.setDocumentMargin(0);
doc.setDocumentMargin(m_itemMargin);
doc.setHtml(index.data().toString());
//qDebug() << doc.toPlainText() << doc.size().toSize();
return doc.size().toSize() + QSize(30, 0); // add margin for the check-box
......
......@@ -31,6 +31,12 @@ public:
void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const override;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void setItemMargin(int m) { m_itemMargin = m; }
int itemMargin() const { return m_itemMargin; }
private:
int m_itemMargin;
};
#endif
......
......@@ -114,7 +114,22 @@ Results::Results(QWidget *parent): QWidget(parent), matches(0), useRegExp(false)
{
setupUi(this);
tree->setItemDelegate(new SPHtmlDelegate(tree));
m_delegate = new SPHtmlDelegate(tree);
tree->setItemDelegate(m_delegate);
}
int Results::itemMargin() const
{
return m_delegate->itemMargin();
}
void Results::setItemMargin(int m)
{
m_delegate->setItemMargin(m);
// trick trigger full relayout
tree->setItemDelegate(nullptr);
tree->setItemDelegate(m_delegate);
tree->update();
}
......@@ -306,6 +321,7 @@ m_mainWindow (mainWin)
connect(m_ui.folderUpButton, &QToolButton::clicked, this, &KatePluginSearchView::navigateFolderUp);
connect(m_ui.currentFolderButton, &QToolButton::clicked, this, &KatePluginSearchView::setCurrentFolder);
connect(m_ui.expandResults, &QToolButton::clicked, this, &KatePluginSearchView::expandResults);
connect(m_ui.itemMargin, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &KatePluginSearchView::marginChanged);
connect(m_ui.searchCombo, &QComboBox::editTextChanged, &m_changeTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
connect(m_ui.matchCase, &QToolButton::toggled, &m_changeTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
......@@ -1522,6 +1538,17 @@ void KatePluginSearchView::expandResults()
}
}
void KatePluginSearchView::marginChanged(int v)
{
m_curResults = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
if (!m_curResults) {
qWarning() << "Results not found";
return;
}
m_curResults->setItemMargin(v);
}
void KatePluginSearchView::updateResultsRootItem()
{
m_curResults = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
......@@ -1852,6 +1879,7 @@ void KatePluginSearchView::readSessionConfig(const KConfigGroup &cg)
m_ui.replaceCombo->addItems(cg.readEntry("Replaces", QStringList()));
m_ui.matchCase->setChecked(cg.readEntry("MatchCase", false));
m_ui.useRegExp->setChecked(cg.readEntry("UseRegExp", false));
m_ui.itemMargin->setValue(cg.readEntry("ItemMargin", 4));
m_ui.expandResults->setChecked(cg.readEntry("ExpandSearchResults", false));
int searchPlaceIndex = cg.readEntry("Place", 1);
......@@ -1897,6 +1925,7 @@ void KatePluginSearchView::writeSessionConfig(KConfigGroup &cg)
cg.writeEntry("MatchCase", m_ui.matchCase->isChecked());
cg.writeEntry("UseRegExp", m_ui.useRegExp->isChecked());
cg.writeEntry("ExpandSearchResults", m_ui.expandResults->isChecked());
cg.writeEntry("ItemMargin", m_ui.itemMargin->value());
cg.writeEntry("Place", m_ui.searchPlaceCombo->currentIndex());
cg.writeEntry("Recursive", m_ui.recursiveCheckBox->isChecked());
......@@ -1942,6 +1971,7 @@ void KatePluginSearchView::addTab()
res->searchPlaceIndex = m_ui.searchPlaceCombo->currentIndex();
res->useRegExp = m_ui.useRegExp->isChecked();
res->matchCase = m_ui.matchCase->isChecked();
res->setItemMargin(m_ui.itemMargin->value());
m_ui.resultTabWidget->addTab(res, QString());
m_ui.resultTabWidget->setCurrentIndex(m_ui.resultTabWidget->count()-1);
m_ui.stackedWidget->setCurrentIndex(0);
......@@ -1986,6 +2016,7 @@ void KatePluginSearchView::resultTabChanged(int index)
m_ui.searchCombo->lineEdit()->setText(m_ui.resultTabWidget->tabText(index));
m_ui.useRegExp->setChecked(res->useRegExp);
m_ui.matchCase->setChecked(res->matchCase);
m_ui.itemMargin->setValue(res->itemMargin());
m_ui.searchPlaceCombo->setCurrentIndex(res->searchPlaceIndex);
m_ui.searchCombo->blockSignals(false);
m_ui.matchCase->blockSignals(false);
......@@ -2014,6 +2045,7 @@ void KatePluginSearchView::onResize(const QSize& size)
m_ui.gridLayout->addWidget(m_ui.replaceLabel, 2, 0);
m_ui.gridLayout->addWidget(m_ui.replaceButton, 3, 0, 1, 2);
m_ui.gridLayout->addWidget(m_ui.replaceCheckedBtn, 3, 2);
m_ui.gridLayout->addWidget(m_ui.itemMargin, 3, 6);
m_ui.gridLayout->addWidget(m_ui.expandResults, 3, 7);
m_ui.gridLayout->addWidget(m_ui.newTabButton, 3, 8);
......@@ -2026,7 +2058,7 @@ void KatePluginSearchView::onResize(const QSize& size)
m_ui.gridLayout->addWidget(m_ui.findLabel, 0, 1);
m_ui.gridLayout->addWidget(m_ui.searchButton, 0, 3);
m_ui.gridLayout->addWidget(m_ui.stopAndNext, 0, 4);
m_ui.gridLayout->addWidget(m_ui.searchPlaceCombo, 0, 5, 1, 4);
m_ui.gridLayout->addWidget(m_ui.searchPlaceCombo, 0, 5, 1, 5);
m_ui.gridLayout->addWidget(m_ui.matchCase, 1, 5);
m_ui.gridLayout->addWidget(m_ui.useRegExp, 1, 6);
......@@ -2034,7 +2066,8 @@ void KatePluginSearchView::onResize(const QSize& size)
m_ui.gridLayout->addWidget(m_ui.replaceLabel, 1, 1);
m_ui.gridLayout->addWidget(m_ui.replaceButton, 1, 3);
m_ui.gridLayout->addWidget(m_ui.replaceCheckedBtn, 1, 4);
m_ui.gridLayout->addWidget(m_ui.expandResults, 1, 8);
m_ui.gridLayout->addWidget(m_ui.itemMargin, 1, 8);
m_ui.gridLayout->addWidget(m_ui.expandResults, 1, 9);
m_ui.gridLayout->addWidget(m_ui.newTabButton, 0, 0);
m_ui.gridLayout->addWidget(m_ui.displayOptions, 1, 0);
......
......@@ -43,6 +43,7 @@
#include "replace_matches.h"
class KateSearchCommand;
class SPHtmlDelegate;
namespace KTextEditor{
class MovingRange;
}
......@@ -58,7 +59,11 @@ public:
bool matchCase;
QString replaceStr;
int searchPlaceIndex;
int itemMargin() const;
void setItemMargin(int m);
QString treeRootText;
private:
SPHtmlDelegate *m_delegate;
};
// This class keeps the focus inside the S&R plugin when pressing tab/shift+tab by overriding focusNextPrevChild()
......@@ -166,6 +171,7 @@ private Q_SLOTS:
void resultTabChanged(int index);
void expandResults();
void marginChanged(int m);
void updateResultsRootItem();
......
......@@ -12,7 +12,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,1,0,0,0,0,0,0,0">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,1,0,0,0,0,0,0,0,0">
<item row="0" column="0">
<widget class="QToolButton" name="newTabButton">
<property name="toolTip">
......@@ -85,7 +85,7 @@
</widget>
</widget>
</item>
<item row="0" column="5" colspan="5">
<item row="0" column="5" colspan="6">
<widget class="QComboBox" name="searchPlaceCombo">
<item>
<property name="text">
......@@ -200,6 +200,16 @@
</spacer>
</item>
<item row="1" column="8">
<widget class="QSpinBox" name="itemMargin">
<property name="toolTip">
<string>Result Item Margin</string>
</property>
<property name="maximum">
<number>4</number>
</property>
</widget>
</item>
<item row="1" column="9">
<widget class="QToolButton" name="expandResults">
<property name="toolTip">
<string>Expand results</string>
......@@ -478,6 +488,7 @@
<tabstop>searchPlaceCombo</tabstop>
<tabstop>matchCase</tabstop>
<tabstop>useRegExp</tabstop>
<tabstop>itemMargin</tabstop>
<tabstop>expandResults</tabstop>
<tabstop>displayOptions</tabstop>
<tabstop>folderRequester</tabstop>
......
Markdown is supported
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