mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-29 22:20:48 +00:00
Qt: add counters to the find dialog
This commit is contained in:
parent
53ca2526ed
commit
3dd45fc859
@ -9,19 +9,27 @@ find_dialog::find_dialog(QTextEdit* edit, QWidget *parent, Qt::WindowFlags f) :
|
|||||||
m_find_bar = new QLineEdit();
|
m_find_bar = new QLineEdit();
|
||||||
m_find_bar->setPlaceholderText(tr("Search..."));
|
m_find_bar->setPlaceholderText(tr("Search..."));
|
||||||
|
|
||||||
|
m_label_count_lines = new QLabel(tr("Counted in lines: -"));
|
||||||
|
m_label_count_total = new QLabel(tr("Counted in total: -"));
|
||||||
|
|
||||||
m_find_first = new QPushButton(tr("First"));
|
m_find_first = new QPushButton(tr("First"));
|
||||||
m_find_last = new QPushButton(tr("Last"));
|
m_find_last = new QPushButton(tr("Last"));
|
||||||
m_find_next = new QPushButton(tr("Next"));
|
m_find_next = new QPushButton(tr("Next"));
|
||||||
m_find_previous = new QPushButton(tr("Previous"));
|
m_find_previous = new QPushButton(tr("Previous"));
|
||||||
|
|
||||||
|
QHBoxLayout* count_layout = new QHBoxLayout();
|
||||||
|
count_layout->addWidget(m_label_count_lines);
|
||||||
|
count_layout->addWidget(m_label_count_total);
|
||||||
|
|
||||||
QHBoxLayout* button_layout = new QHBoxLayout();
|
QHBoxLayout* button_layout = new QHBoxLayout();
|
||||||
button_layout->addWidget(m_find_first);
|
button_layout->addWidget(m_find_first);
|
||||||
button_layout->addWidget(m_find_last);
|
button_layout->addWidget(m_find_last);
|
||||||
button_layout->addWidget(m_find_next);
|
|
||||||
button_layout->addWidget(m_find_previous);
|
button_layout->addWidget(m_find_previous);
|
||||||
|
button_layout->addWidget(m_find_next);
|
||||||
|
|
||||||
QVBoxLayout* layout = new QVBoxLayout();
|
QVBoxLayout* layout = new QVBoxLayout();
|
||||||
layout->addWidget(m_find_bar);
|
layout->addWidget(m_find_bar);
|
||||||
|
layout->addLayout(count_layout);
|
||||||
layout->addLayout(button_layout);
|
layout->addLayout(button_layout);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
@ -37,9 +45,43 @@ find_dialog::~find_dialog()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int find_dialog::count_all()
|
||||||
|
{
|
||||||
|
m_count_lines = 0;
|
||||||
|
m_count_total = 0;
|
||||||
|
|
||||||
|
if (!m_text_edit || m_find_bar->text().isEmpty())
|
||||||
|
{
|
||||||
|
show_count();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTextCursor old_cursor = m_text_edit->textCursor();
|
||||||
|
m_text_edit->moveCursor(QTextCursor::Start);
|
||||||
|
|
||||||
|
int old_line_index = -1;
|
||||||
|
int new_line_index = 0;
|
||||||
|
|
||||||
|
while (m_text_edit->find(m_find_bar->text()))
|
||||||
|
{
|
||||||
|
m_count_total++;
|
||||||
|
new_line_index = m_text_edit->textCursor().blockNumber();
|
||||||
|
|
||||||
|
if (new_line_index != old_line_index)
|
||||||
|
{
|
||||||
|
m_count_lines++;
|
||||||
|
old_line_index = new_line_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_text_edit->setTextCursor(old_cursor);
|
||||||
|
show_count();
|
||||||
|
return m_count_total;
|
||||||
|
}
|
||||||
|
|
||||||
void find_dialog::find_first()
|
void find_dialog::find_first()
|
||||||
{
|
{
|
||||||
if (!m_text_edit || m_find_bar->text().isEmpty())
|
if (count_all() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_text_edit->moveCursor(QTextCursor::Start);
|
m_text_edit->moveCursor(QTextCursor::Start);
|
||||||
@ -48,7 +90,7 @@ void find_dialog::find_first()
|
|||||||
|
|
||||||
void find_dialog::find_last()
|
void find_dialog::find_last()
|
||||||
{
|
{
|
||||||
if (!m_text_edit || m_find_bar->text().isEmpty())
|
if (count_all() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_text_edit->moveCursor(QTextCursor::End);
|
m_text_edit->moveCursor(QTextCursor::End);
|
||||||
@ -57,7 +99,7 @@ void find_dialog::find_last()
|
|||||||
|
|
||||||
void find_dialog::find_next()
|
void find_dialog::find_next()
|
||||||
{
|
{
|
||||||
if (!m_text_edit || m_find_bar->text().isEmpty())
|
if (count_all() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_text_edit->find(m_find_bar->text());
|
m_text_edit->find(m_find_bar->text());
|
||||||
@ -65,8 +107,14 @@ void find_dialog::find_next()
|
|||||||
|
|
||||||
void find_dialog::find_previous()
|
void find_dialog::find_previous()
|
||||||
{
|
{
|
||||||
if (!m_text_edit || m_find_bar->text().isEmpty())
|
if (count_all() <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_text_edit->find(m_find_bar->text(), QTextDocument::FindBackward);
|
m_text_edit->find(m_find_bar->text(), QTextDocument::FindBackward);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void find_dialog::show_count()
|
||||||
|
{
|
||||||
|
m_label_count_lines->setText(tr("Counted in lines: %0").arg(m_count_lines));
|
||||||
|
m_label_count_total->setText(tr("Counted in total: %0").arg(m_count_total));
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
class find_dialog : public QDialog
|
class find_dialog : public QDialog
|
||||||
{
|
{
|
||||||
@ -12,6 +13,10 @@ public:
|
|||||||
~find_dialog();
|
~find_dialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int m_count_lines = 0;
|
||||||
|
int m_count_total = 0;
|
||||||
|
QLabel* m_label_count_lines;
|
||||||
|
QLabel* m_label_count_total;
|
||||||
QTextEdit* m_text_edit;
|
QTextEdit* m_text_edit;
|
||||||
QLineEdit* m_find_bar;
|
QLineEdit* m_find_bar;
|
||||||
QPushButton* m_find_first;
|
QPushButton* m_find_first;
|
||||||
@ -20,8 +25,10 @@ private:
|
|||||||
QPushButton* m_find_previous;
|
QPushButton* m_find_previous;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
int count_all();
|
||||||
void find_first();
|
void find_first();
|
||||||
void find_last();
|
void find_last();
|
||||||
void find_next();
|
void find_next();
|
||||||
void find_previous();
|
void find_previous();
|
||||||
|
void show_count();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user