qBittorrent
AutoExpandableDialog Class Referencefinal

#include <autoexpandabledialog.h>

Inheritance diagram for AutoExpandableDialog:
Collaboration diagram for AutoExpandableDialog:

Public Member Functions

 AutoExpandableDialog (QWidget *parent)
 
 ~AutoExpandableDialog ()
 

Static Public Member Functions

static QString getText (QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode=QLineEdit::Normal, const QString &text={}, bool *ok=nullptr, bool excludeExtension=false, Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
 

Protected Member Functions

void showEvent (QShowEvent *e) override
 

Private Attributes

Ui::AutoExpandableDialog * m_ui
 

Detailed Description

Definition at line 41 of file autoexpandabledialog.h.

Constructor & Destructor Documentation

◆ AutoExpandableDialog()

AutoExpandableDialog::AutoExpandableDialog ( QWidget *  parent)
explicit

Definition at line 35 of file autoexpandabledialog.cpp.

36  : QDialog(parent)
37  , m_ui(new Ui::AutoExpandableDialog)
38 {
39  m_ui->setupUi(this);
40 }
Ui::AutoExpandableDialog * m_ui

References m_ui.

◆ ~AutoExpandableDialog()

AutoExpandableDialog::~AutoExpandableDialog ( )

Definition at line 42 of file autoexpandabledialog.cpp.

43 {
44  delete m_ui;
45 }

References m_ui.

Member Function Documentation

◆ getText()

QString AutoExpandableDialog::getText ( QWidget *  parent,
const QString &  title,
const QString &  label,
QLineEdit::EchoMode  mode = QLineEdit::Normal,
const QString &  text = {},
bool *  ok = nullptr,
bool  excludeExtension = false,
Qt::InputMethodHints  inputMethodHints = Qt::ImhNone 
)
static

Definition at line 47 of file autoexpandabledialog.cpp.

50 {
51  AutoExpandableDialog d(parent);
52  d.setWindowTitle(title);
53  d.m_ui->textLabel->setText(label);
54  d.m_ui->textEdit->setText(text);
55  d.m_ui->textEdit->setEchoMode(mode);
56  d.m_ui->textEdit->setInputMethodHints(inputMethodHints);
57 
58  d.m_ui->textEdit->selectAll();
59  if (excludeExtension)
60  {
61  const QString extension = Utils::Fs::fileExtension(text);
62  if (!extension.isEmpty())
63  d.m_ui->textEdit->setSelection(0, (text.length() - extension.length() - 1));
64  }
65 
66  bool res = d.exec();
67  if (ok)
68  *ok = res;
69 
70  if (!res) return {};
71 
72  return d.m_ui->textEdit->text();
73 }
QString fileExtension(const QString &filename)
Definition: fs.cpp:82

References Utils::Fs::fileExtension(), and m_ui.

Referenced by PluginSelectDialog::askForPluginUrl(), RSSWidget::askNewFolder(), TagFilterWidget::askTagName(), TransferListWidget::askTagsForSelection(), PropertiesWidget::askWebSeed(), MainWindow::defineUILockPassword(), TrackerListWidget::editSelectedTracker(), PropertiesWidget::editWebSeed(), AutomatedRssDownloader::on_addRuleBtn_clicked(), RSSWidget::on_newFeedButton_clicked(), TorrentContentTreeView::renameSelectedFile(), RSSWidget::renameSelectedRSSItem(), AutomatedRssDownloader::renameSelectedRule(), TransferListWidget::renameSelectedTorrent(), and MainWindow::unlockUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showEvent()

void AutoExpandableDialog::showEvent ( QShowEvent *  e)
overrideprotected

Definition at line 75 of file autoexpandabledialog.cpp.

76 {
77  // Overriding showEvent is required for consistent UI with fixed size under custom DPI
78  QDialog::showEvent(e);
79 
80  // Show dialog and resize textbox to fit the text
81  // NOTE: For unknown reason QFontMetrics gets more accurate when called from showEvent.
82  int wd = m_ui->textEdit->fontMetrics().horizontalAdvance(m_ui->textEdit->text()) + 4;
83 
84  if (!windowTitle().isEmpty())
85  {
86  // not really the font metrics in window title, so we enlarge it a bit,
87  // including the small icon and close button width
88  int w = fontMetrics().horizontalAdvance(windowTitle()) * 1.8;
89  wd = std::max(wd, w);
90  }
91 
92  if (!m_ui->textLabel->text().isEmpty())
93  {
94  int w = m_ui->textLabel->fontMetrics().horizontalAdvance(m_ui->textLabel->text());
95  wd = std::max(wd, w);
96  }
97 
98  // Now resize the dialog to fit the contents
99  // max width of text from either of: label, title, textedit
100  // If the value is less than dialog default size, default size is used
101  if (wd > width())
102  {
103  QSize size = {width() - m_ui->verticalLayout->sizeHint().width() + wd, height()};
104  Utils::Gui::resize(this, size);
105  }
106 }
void resize(QWidget *widget, const QSize &newSize={})
Definition: utils.cpp:54

References nova3.nova2dl::e, m_ui, and Utils::Gui::resize().

Here is the call graph for this function:

Member Data Documentation

◆ m_ui

Ui::AutoExpandableDialog* AutoExpandableDialog::m_ui
private

The documentation for this class was generated from the following files: