ctkPathLineEdit.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QComboBox>
  16. #include <QCompleter>
  17. #include <QDebug>
  18. #include <QDirModel>
  19. #include <QFileDialog>
  20. #include <QHBoxLayout>
  21. #include <QLineEdit>
  22. #include <QRegExp>
  23. #include <QRegExpValidator>
  24. #include <QSettings>
  25. #include <QStyleOptionComboBox>
  26. #include <QToolButton>
  27. #include <QApplication>
  28. // CTK includes
  29. #include "ctkPathLineEdit.h"
  30. #include "ctkUtils.h"
  31. //-----------------------------------------------------------------------------
  32. class ctkPathLineEditPrivate
  33. {
  34. Q_DECLARE_PUBLIC(ctkPathLineEdit);
  35. protected:
  36. ctkPathLineEdit* const q_ptr;
  37. public:
  38. ctkPathLineEditPrivate(ctkPathLineEdit& object);
  39. void init();
  40. QSize recomputeSizeHint(QSize& sh)const;
  41. void updateFilter();
  42. void adjustPathLineEditSize();
  43. void createPathLineEditWidget(bool useComboBox);
  44. QString settingKey()const;
  45. QLineEdit* LineEdit;
  46. QComboBox* ComboBox;
  47. QToolButton* BrowseButton; //!< "..." button
  48. int MinimumContentsLength;
  49. ctkPathLineEdit::SizeAdjustPolicy SizeAdjustPolicy;
  50. QString Label; //!< used in file dialogs
  51. QStringList NameFilters; //!< Regular expression (in wildcard mode) used to help the user to complete the line
  52. QDir::Filters Filters; //!< Type of path (file, dir...)
  53. #ifdef USE_QFILEDIALOG_OPTIONS
  54. QFileDialog::Options DialogOptions;
  55. #else
  56. ctkPathLineEdit::Options DialogOptions;
  57. #endif
  58. bool HasValidInput; //!< boolean that stores the old state of valid input
  59. QString SettingKey;
  60. static QString sCurrentDirectory; //!< Content the last value of the current directory
  61. static int sMaxHistory; //!< Size of the history, if the history is full and a new value is added, the oldest value is dropped
  62. mutable QSize SizeHint;
  63. mutable QSize MinimumSizeHint;
  64. };
  65. QString ctkPathLineEditPrivate::sCurrentDirectory = "";
  66. int ctkPathLineEditPrivate::sMaxHistory = 5;
  67. //-----------------------------------------------------------------------------
  68. ctkPathLineEditPrivate::ctkPathLineEditPrivate(ctkPathLineEdit& object)
  69. : q_ptr(&object)
  70. , LineEdit(0)
  71. , ComboBox(0)
  72. , BrowseButton(0)
  73. , MinimumContentsLength(0)
  74. , SizeAdjustPolicy(ctkPathLineEdit::AdjustToContentsOnFirstShow)
  75. , Filters(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Readable)
  76. , HasValidInput(false)
  77. {
  78. }
  79. //-----------------------------------------------------------------------------
  80. void ctkPathLineEditPrivate::init()
  81. {
  82. Q_Q(ctkPathLineEdit);
  83. QHBoxLayout* layout = new QHBoxLayout(q);
  84. layout->setContentsMargins(0,0,0,0);
  85. layout->setSpacing(0); // no space between the combobx and button
  86. this->createPathLineEditWidget(true);
  87. this->BrowseButton = new QToolButton(q);
  88. this->BrowseButton->setText("...");
  89. // Don't vertically stretch the path line edit unnecessary
  90. this->BrowseButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored));
  91. this->BrowseButton->setToolTip(q->tr("Open a dialog"));
  92. QObject::connect(this->BrowseButton,SIGNAL(clicked()),
  93. q, SLOT(browse()));
  94. layout->addWidget(this->BrowseButton);
  95. q->setSizePolicy(QSizePolicy(
  96. QSizePolicy::Expanding, QSizePolicy::Fixed,
  97. QSizePolicy::LineEdit));
  98. }
  99. //------------------------------------------------------------------------------
  100. void ctkPathLineEditPrivate::createPathLineEditWidget(bool useComboBox)
  101. {
  102. Q_Q(ctkPathLineEdit);
  103. QString path = q->currentPath();
  104. if (useComboBox)
  105. {
  106. this->ComboBox = new QComboBox(q);
  107. this->ComboBox->setEditable(true);
  108. this->ComboBox->setInsertPolicy(QComboBox::NoInsert);
  109. this->LineEdit = this->ComboBox->lineEdit();
  110. }
  111. else
  112. {
  113. this->ComboBox = 0;
  114. this->LineEdit = new QLineEdit(q);
  115. }
  116. if (q->layout() && q->layout()->itemAt(0))
  117. {
  118. delete q->layout()->itemAt(0)->widget();
  119. }
  120. qobject_cast<QHBoxLayout*>(q->layout())->insertWidget(
  121. 0,
  122. this->ComboBox ? qobject_cast<QWidget*>(this->ComboBox) :
  123. qobject_cast<QWidget*>(this->LineEdit));
  124. this->updateFilter();
  125. q->retrieveHistory();
  126. q->setCurrentPath(path);
  127. QObject::connect(this->LineEdit, SIGNAL(textChanged(QString)),
  128. q, SLOT(setCurrentDirectory(QString)));
  129. QObject::connect(this->LineEdit, SIGNAL(textChanged(QString)),
  130. q, SLOT(updateHasValidInput()));
  131. q->updateGeometry();
  132. }
  133. //------------------------------------------------------------------------------
  134. QSize ctkPathLineEditPrivate::recomputeSizeHint(QSize& sh)const
  135. {
  136. Q_Q(const ctkPathLineEdit);
  137. if (!sh.isValid())
  138. {
  139. int frame = 0;
  140. if (this->ComboBox)
  141. {
  142. QStyleOptionComboBox option;
  143. int arrowWidth = this->ComboBox->style()->subControlRect(
  144. QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxArrow, this->ComboBox).width()
  145. + (this->ComboBox->hasFrame() ? 2 : 0);
  146. frame = 2 * (this->ComboBox->hasFrame() ? 3 : 0)
  147. + arrowWidth
  148. + 1; // for mac style, not sure why
  149. }
  150. else
  151. {
  152. QStyleOptionFrame option;
  153. int frameWidth = this->LineEdit->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, q);
  154. int horizontalMargin = 2; // QLineEditPrivate::horizontalMargin
  155. // See QLineEdit::sizeHint
  156. frame = 2 * frameWidth
  157. + this->LineEdit->textMargins().left()
  158. + this->LineEdit->textMargins().right()
  159. + this->LineEdit->contentsMargins().left()
  160. + this->LineEdit->contentsMargins().right()
  161. + 2 * horizontalMargin;
  162. }
  163. int browseWidth = 0;
  164. if (q->showBrowseButton())
  165. {
  166. browseWidth = this->BrowseButton->minimumSizeHint().width();
  167. }
  168. // text width
  169. int textWidth = 0;
  170. if (&sh == &this->SizeHint || this->MinimumContentsLength == 0)
  171. {
  172. switch (SizeAdjustPolicy)
  173. {
  174. case ctkPathLineEdit::AdjustToContents:
  175. case ctkPathLineEdit::AdjustToContentsOnFirstShow:
  176. if (this->LineEdit->text().isEmpty())
  177. {
  178. textWidth = 7 * this->LineEdit->fontMetrics().width(QLatin1Char('x'));
  179. }
  180. else
  181. {
  182. textWidth = this->LineEdit->fontMetrics().boundingRect(this->LineEdit->text()).width() + 8;
  183. }
  184. break;
  185. case QComboBox::AdjustToMinimumContentsLength:
  186. default:
  187. ;
  188. }
  189. }
  190. if (this->MinimumContentsLength > 0)
  191. {
  192. textWidth = qMax(textWidth, this->MinimumContentsLength * this->LineEdit->fontMetrics().width(QLatin1Char('X')));
  193. }
  194. int height = (this->ComboBox ? this->ComboBox->minimumSizeHint() :
  195. this->LineEdit->minimumSizeHint()).height();
  196. sh.rwidth() = frame + textWidth + browseWidth;
  197. sh.rheight() = height;
  198. }
  199. return sh.expandedTo(QApplication::globalStrut());
  200. }
  201. //-----------------------------------------------------------------------------
  202. void ctkPathLineEditPrivate::updateFilter()
  203. {
  204. Q_Q(ctkPathLineEdit);
  205. // help completion for the QComboBox::QLineEdit
  206. QCompleter *newCompleter = new QCompleter(q);
  207. newCompleter->setModel(new QDirModel(
  208. ctk::nameFiltersToExtensions(this->NameFilters),
  209. this->Filters | QDir::NoDotAndDotDot | QDir::AllDirs,
  210. QDir::Name|QDir::DirsLast, newCompleter));
  211. this->LineEdit->setCompleter(newCompleter);
  212. // don't accept invalid path
  213. QRegExpValidator* validator = new QRegExpValidator(
  214. ctk::nameFiltersToRegExp(this->NameFilters), q);
  215. this->LineEdit->setValidator(validator);
  216. }
  217. //-----------------------------------------------------------------------------
  218. void ctkPathLineEditPrivate::adjustPathLineEditSize()
  219. {
  220. Q_Q(ctkPathLineEdit);
  221. if (q->sizeAdjustPolicy() == ctkPathLineEdit::AdjustToContents)
  222. {
  223. q->updateGeometry();
  224. q->adjustSize();
  225. q->update();
  226. }
  227. }
  228. //-----------------------------------------------------------------------------
  229. QString ctkPathLineEditPrivate::settingKey()const
  230. {
  231. Q_Q(const ctkPathLineEdit);
  232. return QString("ctkPathLineEdit/") +
  233. (this->SettingKey.isEmpty() ? q->objectName() : this->SettingKey);
  234. }
  235. //-----------------------------------------------------------------------------
  236. ctkPathLineEdit::ctkPathLineEdit(QWidget *parentWidget)
  237. : QWidget(parentWidget)
  238. , d_ptr(new ctkPathLineEditPrivate(*this))
  239. {
  240. Q_D(ctkPathLineEdit);
  241. d->init();
  242. this->setNameFilters(nameFilters());
  243. this->setFilters(filters());
  244. }
  245. //-----------------------------------------------------------------------------
  246. ctkPathLineEdit::ctkPathLineEdit(const QString& label,
  247. const QStringList& nameFilters,
  248. Filters filters,
  249. QWidget *parentWidget)
  250. : QWidget(parentWidget)
  251. , d_ptr(new ctkPathLineEditPrivate(*this))
  252. {
  253. Q_D(ctkPathLineEdit);
  254. d->init();
  255. this->setLabel(label);
  256. this->setNameFilters(nameFilters);
  257. this->setFilters(filters);
  258. }
  259. //-----------------------------------------------------------------------------
  260. ctkPathLineEdit::~ctkPathLineEdit()
  261. {
  262. }
  263. //-----------------------------------------------------------------------------
  264. void ctkPathLineEdit::setLabel(const QString &label)
  265. {
  266. Q_D(ctkPathLineEdit);
  267. d->Label = label;
  268. }
  269. //-----------------------------------------------------------------------------
  270. const QString& ctkPathLineEdit::label()const
  271. {
  272. Q_D(const ctkPathLineEdit);
  273. return d->Label;
  274. }
  275. //-----------------------------------------------------------------------------
  276. void ctkPathLineEdit::setNameFilters(const QStringList &nameFilters)
  277. {
  278. Q_D(ctkPathLineEdit);
  279. d->NameFilters = nameFilters;
  280. d->updateFilter();
  281. }
  282. //-----------------------------------------------------------------------------
  283. const QStringList& ctkPathLineEdit::nameFilters()const
  284. {
  285. Q_D(const ctkPathLineEdit);
  286. return d->NameFilters;
  287. }
  288. //-----------------------------------------------------------------------------
  289. void ctkPathLineEdit::setFilters(const Filters &filters)
  290. {
  291. Q_D(ctkPathLineEdit);
  292. d->Filters = QFlags<QDir::Filter>(static_cast<int>(filters));
  293. d->updateFilter();
  294. }
  295. //-----------------------------------------------------------------------------
  296. ctkPathLineEdit::Filters ctkPathLineEdit::filters()const
  297. {
  298. Q_D(const ctkPathLineEdit);
  299. return QFlags<ctkPathLineEdit::Filter>(static_cast<int>(d->Filters));
  300. }
  301. //-----------------------------------------------------------------------------
  302. #ifdef USE_QFILEDIALOG_OPTIONS
  303. void ctkPathLineEdit::setOptions(const QFileDialog::Options& dialogOptions)
  304. #else
  305. void ctkPathLineEdit::setOptions(const Options& dialogOptions)
  306. #endif
  307. {
  308. Q_D(ctkPathLineEdit);
  309. d->DialogOptions = dialogOptions;
  310. }
  311. //-----------------------------------------------------------------------------
  312. #ifdef USE_QFILEDIALOG_OPTIONS
  313. const QFileDialog::Options& ctkPathLineEdit::options()const
  314. #else
  315. const ctkPathLineEdit::Options& ctkPathLineEdit::options()const
  316. #endif
  317. {
  318. Q_D(const ctkPathLineEdit);
  319. return d->DialogOptions;
  320. }
  321. //-----------------------------------------------------------------------------
  322. void ctkPathLineEdit::browse()
  323. {
  324. Q_D(ctkPathLineEdit);
  325. QString path = "";
  326. if ( d->Filters & QDir::Files ) //file
  327. {
  328. if ( d->Filters & QDir::Writable) // load or save
  329. {
  330. path = QFileDialog::getSaveFileName(
  331. this,
  332. tr("Select a file to save "),
  333. this->currentPath().isEmpty() ? ctkPathLineEditPrivate::sCurrentDirectory :
  334. this->currentPath(),
  335. d->NameFilters.join(";;"),
  336. 0,
  337. #ifdef USE_QFILEDIALOG_OPTIONS
  338. d->DialogOptions);
  339. #else
  340. QFlags<QFileDialog::Option>(int(d->DialogOptions)));
  341. #endif
  342. }
  343. else
  344. {
  345. path = QFileDialog::getOpenFileName(
  346. this,
  347. QString("Open a file"),
  348. this->currentPath().isEmpty()? ctkPathLineEditPrivate::sCurrentDirectory :
  349. this->currentPath(),
  350. d->NameFilters.join(";;"),
  351. 0,
  352. #ifdef USE_QFILEDIALOG_OPTIONS
  353. d->DialogOptions);
  354. #else
  355. QFlags<QFileDialog::Option>(int(d->DialogOptions)));
  356. #endif
  357. }
  358. }
  359. else //directory
  360. {
  361. path = QFileDialog::getExistingDirectory(
  362. this,
  363. QString("Select a directory..."),
  364. this->currentPath().isEmpty() ? ctkPathLineEditPrivate::sCurrentDirectory :
  365. this->currentPath(),
  366. #ifdef USE_QFILEDIALOG_OPTIONS
  367. d->DialogOptions);
  368. #else
  369. QFlags<QFileDialog::Option>(int(d->DialogOptions)));
  370. #endif
  371. }
  372. if (path.isEmpty())
  373. {
  374. return;
  375. }
  376. this->setCurrentPath(path);
  377. }
  378. //-----------------------------------------------------------------------------
  379. void ctkPathLineEdit::retrieveHistory()
  380. {
  381. Q_D(ctkPathLineEdit);
  382. if (d->ComboBox == 0)
  383. {
  384. return;
  385. }
  386. QString path = this->currentPath();
  387. bool wasBlocking = this->blockSignals(true);
  388. d->ComboBox->clear();
  389. // fill the combobox using the QSettings
  390. QSettings settings;
  391. QString key = d->settingKey();
  392. const QStringList history = settings.value(key).toStringList();
  393. foreach(const QString& path, history)
  394. {
  395. d->ComboBox->addItem(path);
  396. if (d->ComboBox->count() >= ctkPathLineEditPrivate::sMaxHistory)
  397. {
  398. break;
  399. }
  400. }
  401. // Restore path or select the most recent file location if none set.
  402. if (path.isEmpty())
  403. {
  404. this->blockSignals(wasBlocking);
  405. d->ComboBox->setCurrentIndex(0);
  406. }
  407. else
  408. {
  409. this->setCurrentPath(path);
  410. this->blockSignals(wasBlocking);
  411. }
  412. }
  413. //-----------------------------------------------------------------------------
  414. void ctkPathLineEdit::addCurrentPathToHistory()
  415. {
  416. Q_D(ctkPathLineEdit);
  417. if (d->ComboBox == 0 ||
  418. this->currentPath().isEmpty())
  419. {
  420. return;
  421. }
  422. QSettings settings;
  423. //keep the same values, add the current value
  424. //if more than m_MaxHistory entrees, drop the oldest.
  425. QString key = d->settingKey();
  426. QStringList history = settings.value(key).toStringList();
  427. if (history.contains(this->currentPath()))
  428. {
  429. history.removeAll(this->currentPath());
  430. }
  431. history.push_front(this->currentPath());
  432. settings.setValue(key, history);
  433. int index = d->ComboBox->findText(this->currentPath());
  434. if (index >= 0)
  435. {
  436. d->ComboBox->removeItem(index);
  437. }
  438. while (d->ComboBox->count() >= ctkPathLineEditPrivate::sMaxHistory)
  439. {
  440. d->ComboBox->removeItem(d->ComboBox->count() - 1);
  441. }
  442. d->ComboBox->insertItem(0, this->currentPath());
  443. }
  444. //------------------------------------------------------------------------------
  445. void ctkPathLineEdit::setCurrentFileExtension(const QString& extension)
  446. {
  447. QString filename = this->currentPath();
  448. QFileInfo fileInfo(filename);
  449. if (!fileInfo.suffix().isEmpty())
  450. {
  451. filename.replace(fileInfo.suffix(), extension);
  452. }
  453. else
  454. {
  455. filename.append(QString(".") + extension);
  456. }
  457. this->setCurrentPath(filename);
  458. }
  459. //------------------------------------------------------------------------------
  460. QComboBox* ctkPathLineEdit::comboBox() const
  461. {
  462. Q_D(const ctkPathLineEdit);
  463. return d->ComboBox;
  464. }
  465. //------------------------------------------------------------------------------
  466. QString ctkPathLineEdit::currentPath()const
  467. {
  468. Q_D(const ctkPathLineEdit);
  469. return d->LineEdit ? d->LineEdit->text() : QString();
  470. }
  471. //------------------------------------------------------------------------------
  472. void ctkPathLineEdit::setCurrentPath(const QString& path)
  473. {
  474. Q_D(ctkPathLineEdit);
  475. d->LineEdit->setText(path);
  476. }
  477. //------------------------------------------------------------------------------
  478. void ctkPathLineEdit::setCurrentDirectory(const QString& directory)
  479. {
  480. ctkPathLineEditPrivate::sCurrentDirectory = directory;
  481. }
  482. //------------------------------------------------------------------------------
  483. void ctkPathLineEdit::updateHasValidInput()
  484. {
  485. Q_D(ctkPathLineEdit);
  486. bool oldHasValidInput = d->HasValidInput;
  487. d->HasValidInput = d->LineEdit->hasAcceptableInput();
  488. if (d->HasValidInput)
  489. {
  490. QFileInfo fileInfo(this->currentPath());
  491. ctkPathLineEditPrivate::sCurrentDirectory =
  492. fileInfo.isFile() ? fileInfo.absolutePath() : fileInfo.absoluteFilePath();
  493. emit currentPathChanged(this->currentPath());
  494. }
  495. if (d->HasValidInput != oldHasValidInput)
  496. {
  497. emit validInputChanged(d->HasValidInput);
  498. }
  499. if (d->SizeAdjustPolicy == AdjustToContents)
  500. {
  501. d->SizeHint = QSize();
  502. d->adjustPathLineEditSize();
  503. this->updateGeometry();
  504. }
  505. }
  506. //------------------------------------------------------------------------------
  507. QString ctkPathLineEdit::settingKey()const
  508. {
  509. Q_D(const ctkPathLineEdit);
  510. return d->SettingKey;
  511. }
  512. //------------------------------------------------------------------------------
  513. void ctkPathLineEdit::setSettingKey(const QString& key)
  514. {
  515. Q_D(ctkPathLineEdit);
  516. d->SettingKey = key;
  517. this->retrieveHistory();
  518. }
  519. //------------------------------------------------------------------------------
  520. bool ctkPathLineEdit::showBrowseButton()const
  521. {
  522. Q_D(const ctkPathLineEdit);
  523. return d->BrowseButton->isVisibleTo(const_cast<ctkPathLineEdit*>(this));
  524. }
  525. //------------------------------------------------------------------------------
  526. void ctkPathLineEdit::setShowBrowseButton(bool visible)
  527. {
  528. Q_D(ctkPathLineEdit);
  529. d->BrowseButton->setVisible(visible);
  530. }
  531. //------------------------------------------------------------------------------
  532. bool ctkPathLineEdit::showHistoryButton()const
  533. {
  534. Q_D(const ctkPathLineEdit);
  535. return d->ComboBox ? true: false;
  536. }
  537. //------------------------------------------------------------------------------
  538. void ctkPathLineEdit::setShowHistoryButton(bool visible)
  539. {
  540. Q_D(ctkPathLineEdit);
  541. d->createPathLineEditWidget(visible);
  542. }
  543. //------------------------------------------------------------------------------
  544. ctkPathLineEdit::SizeAdjustPolicy ctkPathLineEdit::sizeAdjustPolicy() const
  545. {
  546. Q_D(const ctkPathLineEdit);
  547. return d->SizeAdjustPolicy;
  548. }
  549. //------------------------------------------------------------------------------
  550. void ctkPathLineEdit::setSizeAdjustPolicy(ctkPathLineEdit::SizeAdjustPolicy policy)
  551. {
  552. Q_D(ctkPathLineEdit);
  553. if (policy == d->SizeAdjustPolicy)
  554. return;
  555. d->SizeAdjustPolicy = policy;
  556. d->SizeHint = QSize();
  557. d->adjustPathLineEditSize();
  558. this->updateGeometry();
  559. }
  560. //------------------------------------------------------------------------------
  561. int ctkPathLineEdit::minimumContentsLength()const
  562. {
  563. Q_D(const ctkPathLineEdit);
  564. return d->MinimumContentsLength;
  565. }
  566. //------------------------------------------------------------------------------
  567. void ctkPathLineEdit::setMinimumContentsLength(int length)
  568. {
  569. Q_D(ctkPathLineEdit);
  570. if (d->MinimumContentsLength == length || length < 0) return;
  571. d->MinimumContentsLength = length;
  572. if (d->SizeAdjustPolicy == AdjustToContents ||
  573. d->SizeAdjustPolicy == AdjustToMinimumContentsLength)
  574. {
  575. d->SizeHint = QSize();
  576. d->adjustPathLineEditSize();
  577. this->updateGeometry();
  578. }
  579. }
  580. //------------------------------------------------------------------------------
  581. QSize ctkPathLineEdit::minimumSizeHint()const
  582. {
  583. Q_D(const ctkPathLineEdit);
  584. return d->recomputeSizeHint(d->MinimumSizeHint);
  585. }
  586. //------------------------------------------------------------------------------
  587. QSize ctkPathLineEdit::sizeHint()const
  588. {
  589. Q_D(const ctkPathLineEdit);
  590. return d->recomputeSizeHint(d->SizeHint);
  591. }