ctkPathListButtonsWidget.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) University College London.
  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. #include <iostream>
  15. // Qt includes
  16. #include <QDebug>
  17. #include <QFileDialog>
  18. #include <QSortFilterProxyModel>
  19. #include <QFileSystemModel>
  20. #include <QFileInfo>
  21. #include <QMessageBox>
  22. // CTK includes
  23. #include "ctkPathListButtonsWidget.h"
  24. #include "ctkPathListButtonsWidget_p.h"
  25. //-----------------------------------------------------------------------------
  26. // ctkPathListButtonsWidgetPrivate methods
  27. //-----------------------------------------------------------------------------
  28. ctkPathListButtonsWidgetPrivate::~ctkPathListButtonsWidgetPrivate()
  29. {
  30. }
  31. //-----------------------------------------------------------------------------
  32. ctkPathListButtonsWidgetPrivate::ctkPathListButtonsWidgetPrivate(ctkPathListButtonsWidget& object)
  33. : QObject(&object)
  34. , q_ptr(&object)
  35. , PathListWidget(NULL)
  36. {
  37. }
  38. //-----------------------------------------------------------------------------
  39. void ctkPathListButtonsWidgetPrivate::init()
  40. {
  41. Q_Q(ctkPathListButtonsWidget);
  42. this->setupUi(q);
  43. q->unsetIconAddFilesButton();
  44. q->unsetIconAddDirectoryButton();
  45. q->unsetIconRemoveButton();
  46. q->unsetIconEditButton();
  47. }
  48. //-----------------------------------------------------------------------------
  49. void ctkPathListButtonsWidgetPrivate::setupUi(QWidget * widget)
  50. {
  51. this->Ui_ctkPathListButtonsWidget::setupUi(widget);
  52. connect(this->AddFilesButton, SIGNAL(clicked()), SLOT(on_AddFilesButton_clicked()));
  53. connect(this->AddDirectoryButton, SIGNAL(clicked()), SLOT(on_AddDirButton_clicked()));
  54. connect(this->RemoveButton, SIGNAL(clicked()), SLOT(on_RemoveButton_clicked()));
  55. connect(this->EditButton, SIGNAL(clicked()), SLOT(on_EditButton_clicked()));
  56. }
  57. //-----------------------------------------------------------------------------
  58. void ctkPathListButtonsWidgetPrivate::on_AddFilesButton_clicked()
  59. {
  60. if (!this->PathListWidget) return;
  61. QStringList paths = this->openAddFilesDialog(true);
  62. this->addPathsWithWarningMessage(paths);
  63. }
  64. //-----------------------------------------------------------------------------
  65. void ctkPathListButtonsWidgetPrivate::on_AddDirButton_clicked()
  66. {
  67. if (!this->PathListWidget) return;
  68. QStringList paths = this->openAddDirDialog();
  69. this->addPathsWithWarningMessage(paths);
  70. }
  71. //-----------------------------------------------------------------------------
  72. void ctkPathListButtonsWidgetPrivate::on_RemoveButton_clicked()
  73. {
  74. if (!this->PathListWidget) return;
  75. this->PathListWidget->removeSelectedPaths();
  76. }
  77. //-----------------------------------------------------------------------------
  78. void ctkPathListButtonsWidgetPrivate::on_EditButton_clicked()
  79. {
  80. Q_Q(ctkPathListButtonsWidget);
  81. if (!this->PathListWidget) return;
  82. QString currentPath = this->PathListWidget->currentPath(true);
  83. QStringList paths;
  84. if (this->PathListWidget->isFile(currentPath))
  85. {
  86. paths = this->openAddFilesDialog(false);
  87. }
  88. else
  89. {
  90. paths = this->openAddDirDialog();
  91. }
  92. if (!paths.isEmpty())
  93. {
  94. if (!this->PathListWidget->editPath(currentPath, paths.front()))
  95. {
  96. QMessageBox::information(q, tr("Editing the path failed"),
  97. QString(tr("Failed to change path:\n\n%1\n\nto path\n\n%2\n\nPlease check your permissions."))
  98. .arg(currentPath).arg(paths.front()));
  99. }
  100. }
  101. }
  102. //-----------------------------------------------------------------------------
  103. void ctkPathListButtonsWidgetPrivate::on_PathListWidget_selectionChanged(const QItemSelection &selected,
  104. const QItemSelection &deselected)
  105. {
  106. Q_UNUSED(selected)
  107. Q_UNUSED(deselected)
  108. bool hasSelection = this->PathListWidget->selectionModel()->hasSelection();
  109. this->EditButton->setEnabled(hasSelection);
  110. this->RemoveButton->setEnabled(hasSelection);
  111. }
  112. //-----------------------------------------------------------------------------
  113. QStringList ctkPathListButtonsWidgetPrivate::openAddFilesDialog(bool multiple)
  114. {
  115. Q_Q(ctkPathListButtonsWidget);
  116. if (!this->PathListWidget) return QStringList();
  117. QString caption;
  118. if (multiple)
  119. {
  120. caption = tr("Select one or more files");
  121. }
  122. else
  123. {
  124. caption = tr("Select a file");
  125. }
  126. QFileDialog fileDialog(q, caption);
  127. fileDialog.setReadOnly(true);
  128. if (multiple)
  129. {
  130. fileDialog.setFileMode(QFileDialog::ExistingFiles);
  131. }
  132. else
  133. {
  134. fileDialog.setFileMode(QFileDialog::ExistingFile);
  135. }
  136. QString currentPath = this->PathListWidget->currentPath(true);
  137. currentPath = currentPath.left(currentPath.lastIndexOf('/') + 1);
  138. if (!currentPath.isEmpty())
  139. {
  140. fileDialog.setDirectory(currentPath);
  141. }
  142. // We use a proxy model as a workaround for the broken QFileDialog::setFilter() method.
  143. // See for example https://bugreports.qt-project.org/browse/QTBUG-10244
  144. class FileFilterProxyModel : public QSortFilterProxyModel
  145. {
  146. public:
  147. FileFilterProxyModel(ctkPathListWidget::PathOptions fileOptions)
  148. : FileOptions(fileOptions)
  149. {}
  150. protected:
  151. virtual bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
  152. {
  153. QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
  154. QFileSystemModel* fileModel = qobject_cast<QFileSystemModel*>(sourceModel());
  155. QFileInfo fileInfo = fileModel->fileInfo(sourceIndex);
  156. if(fileInfo.isFile())
  157. {
  158. if (FileOptions.testFlag(ctkPathListWidget::Readable) &&
  159. !fileInfo.isReadable())
  160. {
  161. return false;
  162. }
  163. if (FileOptions.testFlag(ctkPathListWidget::Writable) &&
  164. !fileInfo.isWritable())
  165. {
  166. return false;
  167. }
  168. if (FileOptions.testFlag(ctkPathListWidget::Executable)&&
  169. !fileInfo.isExecutable())
  170. {
  171. return false;
  172. }
  173. return true;
  174. }
  175. else
  176. {
  177. // Show all readable directories
  178. return fileInfo.isReadable();
  179. }
  180. }
  181. private:
  182. ctkPathListWidget::PathOptions FileOptions;
  183. };
  184. fileDialog.setProxyModel(new FileFilterProxyModel(this->PathListWidget->fileOptions()));
  185. if (fileDialog.exec() == QDialog::Accepted)
  186. {
  187. return fileDialog.selectedFiles();
  188. }
  189. return QStringList();
  190. }
  191. //-----------------------------------------------------------------------------
  192. QStringList ctkPathListButtonsWidgetPrivate::openAddDirDialog()
  193. {
  194. Q_Q(ctkPathListButtonsWidget);
  195. if (!this->PathListWidget) return QStringList();
  196. QString caption = tr("Select a directory");
  197. QFileDialog fileDialog(q, caption);
  198. fileDialog.setFileMode(QFileDialog::Directory);
  199. fileDialog.setOption(QFileDialog::ShowDirsOnly);
  200. QString currentPath = this->PathListWidget->currentPath(true);
  201. if (!currentPath.isEmpty())
  202. {
  203. fileDialog.setDirectory(currentPath);
  204. }
  205. // We use a proxy model as a workaround for the broken QFileDialog::setFilter() method.
  206. // See for example https://bugreports.qt-project.org/browse/QTBUG-10244
  207. class DirFilterProxyModel : public QSortFilterProxyModel
  208. {
  209. public:
  210. DirFilterProxyModel(ctkPathListWidget::PathOptions dirOptions)
  211. : DirOptions(dirOptions)
  212. {}
  213. protected:
  214. virtual bool filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const
  215. {
  216. QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
  217. QFileSystemModel* fileModel = qobject_cast<QFileSystemModel*>(sourceModel());
  218. QFileInfo fileInfo = fileModel->fileInfo(sourceIndex);
  219. if (DirOptions.testFlag(ctkPathListWidget::Readable) &&
  220. !fileInfo.isReadable())
  221. {
  222. return false;
  223. }
  224. // Do not check for the Writable flag, since it makes navigation from
  225. // non-writable folders to writable sub-folders hard.
  226. // if (DirOptions.testFlag(ctkPathListWidget::Writable) &&
  227. // !fileInfo.isWritable())
  228. // {
  229. // return false;
  230. // }
  231. return true;
  232. }
  233. private:
  234. ctkPathListWidget::PathOptions DirOptions;
  235. };
  236. fileDialog.setProxyModel(new DirFilterProxyModel(this->PathListWidget->directoryOptions()));
  237. if (fileDialog.exec() == QDialog::Accepted)
  238. {
  239. return fileDialog.selectedFiles();
  240. }
  241. return QStringList();
  242. }
  243. //-----------------------------------------------------------------------------
  244. void ctkPathListButtonsWidgetPrivate::addPathsWithWarningMessage(const QStringList& paths)
  245. {
  246. Q_Q(ctkPathListButtonsWidget);
  247. QStringList addedPaths = this->PathListWidget->addPaths(paths);
  248. if (addedPaths != paths)
  249. {
  250. QString problematicPaths;
  251. foreach(const QString& path, paths)
  252. {
  253. if (!addedPaths.contains(path) && !this->PathListWidget->contains(path))
  254. {
  255. problematicPaths += path + '\n';
  256. }
  257. }
  258. if (!problematicPaths.isEmpty())
  259. {
  260. QMessageBox::information(q, tr("Adding paths failed"),
  261. QString(tr("Failed to add the following paths:\n\n%1\nPlease check your permissions."))
  262. .arg(problematicPaths));
  263. }
  264. }
  265. }
  266. //-----------------------------------------------------------------------------
  267. // ctkPathListButtonsWidget methods
  268. //-----------------------------------------------------------------------------
  269. ctkPathListButtonsWidget::~ctkPathListButtonsWidget()
  270. {
  271. }
  272. void ctkPathListButtonsWidget::init(ctkPathListWidget *pathListWidget)
  273. {
  274. Q_D(ctkPathListButtonsWidget);
  275. d->PathListWidget = pathListWidget;
  276. if (d->PathListWidget->selectionModel()->selectedIndexes().isEmpty())
  277. {
  278. d->RemoveButton->setEnabled(false);
  279. d->EditButton->setEnabled(false);
  280. }
  281. switch(d->PathListWidget->mode())
  282. {
  283. case ctkPathListWidget::FilesOnly:
  284. d->AddDirectoryButton->setVisible(false);
  285. break;
  286. case ctkPathListWidget::DirectoriesOnly:
  287. d->AddFilesButton->setVisible(false);
  288. break;
  289. default:
  290. break;
  291. }
  292. connect(d->PathListWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
  293. d, SLOT(on_PathListWidget_selectionChanged(QItemSelection,QItemSelection)));
  294. connect(d->PathListWidget, SIGNAL(pathActivated(QString)), d, SLOT(on_EditButton_clicked()));
  295. }
  296. //-----------------------------------------------------------------------------
  297. ctkPathListButtonsWidget::ctkPathListButtonsWidget(QWidget* newParent)
  298. : Superclass(newParent)
  299. , d_ptr(new ctkPathListButtonsWidgetPrivate(*this))
  300. {
  301. Q_D(ctkPathListButtonsWidget);
  302. d->init();
  303. }
  304. //-----------------------------------------------------------------------------
  305. bool ctkPathListButtonsWidget::isAddFilesButtonVisible() const
  306. {
  307. Q_D(const ctkPathListButtonsWidget);
  308. return d->AddFilesButton->isVisible();
  309. }
  310. //-----------------------------------------------------------------------------
  311. void ctkPathListButtonsWidget::setAddFilesButtonVisible(bool visible)
  312. {
  313. Q_D(ctkPathListButtonsWidget);
  314. d->AddFilesButton->setVisible(visible);
  315. }
  316. //-----------------------------------------------------------------------------
  317. bool ctkPathListButtonsWidget::isAddDirectoryButtonVisible() const
  318. {
  319. Q_D(const ctkPathListButtonsWidget);
  320. return d->AddDirectoryButton->isVisible();
  321. }
  322. //-----------------------------------------------------------------------------
  323. void ctkPathListButtonsWidget::setAddDirectoryButtonVisible(bool visible)
  324. {
  325. Q_D(ctkPathListButtonsWidget);
  326. d->AddDirectoryButton->setVisible(visible);
  327. }
  328. //-----------------------------------------------------------------------------
  329. bool ctkPathListButtonsWidget::isRemoveButtonVisible() const
  330. {
  331. Q_D(const ctkPathListButtonsWidget);
  332. return d->RemoveButton->isVisible();
  333. }
  334. //-----------------------------------------------------------------------------
  335. void ctkPathListButtonsWidget::setRemoveButtonVisible(bool visible)
  336. {
  337. Q_D(ctkPathListButtonsWidget);
  338. d->RemoveButton->setVisible(visible);
  339. }
  340. //-----------------------------------------------------------------------------
  341. bool ctkPathListButtonsWidget::isEditButtonVisible() const
  342. {
  343. Q_D(const ctkPathListButtonsWidget);
  344. return d->EditButton->isVisible();
  345. }
  346. //-----------------------------------------------------------------------------
  347. void ctkPathListButtonsWidget::setEditButtonVisible(bool visible)
  348. {
  349. Q_D(ctkPathListButtonsWidget);
  350. d->EditButton->setVisible(visible);
  351. }
  352. //-----------------------------------------------------------------------------
  353. QString ctkPathListButtonsWidget::textAddFilesButton() const
  354. {
  355. Q_D(const ctkPathListButtonsWidget);
  356. return d->AddFilesButton->text();
  357. }
  358. //-----------------------------------------------------------------------------
  359. QString ctkPathListButtonsWidget::textAddDirectoryButton() const
  360. {
  361. Q_D(const ctkPathListButtonsWidget);
  362. return d->AddDirectoryButton->text();
  363. }
  364. //-----------------------------------------------------------------------------
  365. QString ctkPathListButtonsWidget::textRemoveButton() const
  366. {
  367. Q_D(const ctkPathListButtonsWidget);
  368. return d->RemoveButton->text();
  369. }
  370. //-----------------------------------------------------------------------------
  371. QString ctkPathListButtonsWidget::textEditButton() const
  372. {
  373. Q_D(const ctkPathListButtonsWidget);
  374. return d->EditButton->text();
  375. }
  376. //-----------------------------------------------------------------------------
  377. void ctkPathListButtonsWidget::setTextAddFilesButton(const QString& text)
  378. {
  379. Q_D(ctkPathListButtonsWidget);
  380. d->AddFilesButton->setText(text);
  381. }
  382. //-----------------------------------------------------------------------------
  383. void ctkPathListButtonsWidget::setTextAddDirectoryButton(const QString& text)
  384. {
  385. Q_D(ctkPathListButtonsWidget);
  386. d->AddDirectoryButton->setText(text);
  387. }
  388. //-----------------------------------------------------------------------------
  389. void ctkPathListButtonsWidget::setTextRemoveButton(const QString& text)
  390. {
  391. Q_D(ctkPathListButtonsWidget);
  392. d->RemoveButton->setText(text);
  393. }
  394. //-----------------------------------------------------------------------------
  395. void ctkPathListButtonsWidget::setTextEditButton(const QString& text)
  396. {
  397. Q_D(ctkPathListButtonsWidget);
  398. d->EditButton->setText(text);
  399. }
  400. //-----------------------------------------------------------------------------
  401. QString ctkPathListButtonsWidget::toolTipAddFilesButton() const
  402. {
  403. Q_D(const ctkPathListButtonsWidget);
  404. return d->AddFilesButton->toolTip();
  405. }
  406. //-----------------------------------------------------------------------------
  407. QString ctkPathListButtonsWidget::toolTipAddDirectoryButton() const
  408. {
  409. Q_D(const ctkPathListButtonsWidget);
  410. return d->AddDirectoryButton->toolTip();
  411. }
  412. //-----------------------------------------------------------------------------
  413. QString ctkPathListButtonsWidget::toolTipRemoveButton() const
  414. {
  415. Q_D(const ctkPathListButtonsWidget);
  416. return d->RemoveButton->toolTip();
  417. }
  418. //-----------------------------------------------------------------------------
  419. QString ctkPathListButtonsWidget::toolTipEditButton() const
  420. {
  421. Q_D(const ctkPathListButtonsWidget);
  422. return d->EditButton->toolTip();
  423. }
  424. //-----------------------------------------------------------------------------
  425. void ctkPathListButtonsWidget::setToolTipAddFilesButton(const QString& toolTip)
  426. {
  427. Q_D(ctkPathListButtonsWidget);
  428. d->AddFilesButton->setToolTip(toolTip);
  429. }
  430. //-----------------------------------------------------------------------------
  431. void ctkPathListButtonsWidget::setToolTipAddDirectoryButton(const QString& toolTip)
  432. {
  433. Q_D(ctkPathListButtonsWidget);
  434. d->AddDirectoryButton->setToolTip(toolTip);
  435. }
  436. //-----------------------------------------------------------------------------
  437. void ctkPathListButtonsWidget::setToolTipRemoveButton(const QString& toolTip)
  438. {
  439. Q_D(ctkPathListButtonsWidget);
  440. d->RemoveButton->setToolTip(toolTip);
  441. }
  442. //-----------------------------------------------------------------------------
  443. void ctkPathListButtonsWidget::setToolTipEditButton(const QString& toolTip)
  444. {
  445. Q_D(ctkPathListButtonsWidget);
  446. d->EditButton->setToolTip(toolTip);
  447. }
  448. //-----------------------------------------------------------------------------
  449. QIcon ctkPathListButtonsWidget::iconAddFilesButton() const
  450. {
  451. Q_D(const ctkPathListButtonsWidget);
  452. return d->AddFilesButton->icon();
  453. }
  454. //-----------------------------------------------------------------------------
  455. QIcon ctkPathListButtonsWidget::iconAddDirectoryButton() const
  456. {
  457. Q_D(const ctkPathListButtonsWidget);
  458. return d->AddDirectoryButton->icon();
  459. }
  460. //-----------------------------------------------------------------------------
  461. QIcon ctkPathListButtonsWidget::iconRemoveButton() const
  462. {
  463. Q_D(const ctkPathListButtonsWidget);
  464. return d->RemoveButton->icon();
  465. }
  466. //-----------------------------------------------------------------------------
  467. QIcon ctkPathListButtonsWidget::iconEditButton() const
  468. {
  469. Q_D(const ctkPathListButtonsWidget);
  470. return d->EditButton->icon();
  471. }
  472. //-----------------------------------------------------------------------------
  473. void ctkPathListButtonsWidget::setIconAddFilesButton(const QIcon& icon)
  474. {
  475. Q_D(ctkPathListButtonsWidget);
  476. d->AddFilesButton->setIcon(icon);
  477. }
  478. //-----------------------------------------------------------------------------
  479. void ctkPathListButtonsWidget::setIconAddDirectoryButton(const QIcon& icon)
  480. {
  481. Q_D(ctkPathListButtonsWidget);
  482. d->AddDirectoryButton->setIcon(icon);
  483. }
  484. //-----------------------------------------------------------------------------
  485. void ctkPathListButtonsWidget::setIconRemoveButton(const QIcon& icon)
  486. {
  487. Q_D(ctkPathListButtonsWidget);
  488. d->RemoveButton->setIcon(icon);
  489. }
  490. //-----------------------------------------------------------------------------
  491. void ctkPathListButtonsWidget::setIconEditButton(const QIcon& icon)
  492. {
  493. Q_D(ctkPathListButtonsWidget);
  494. d->EditButton->setIcon(icon);
  495. }
  496. //-----------------------------------------------------------------------------
  497. void ctkPathListButtonsWidget::unsetIconAddFilesButton()
  498. {
  499. Q_D(ctkPathListButtonsWidget);
  500. d->AddFilesButton->setIcon(QIcon(":/Icons/plus.png"));
  501. }
  502. //-----------------------------------------------------------------------------
  503. void ctkPathListButtonsWidget::unsetIconAddDirectoryButton()
  504. {
  505. Q_D(ctkPathListButtonsWidget);
  506. d->AddDirectoryButton->setIcon(QIcon(":/Icons/plus.png"));
  507. }
  508. //-----------------------------------------------------------------------------
  509. void ctkPathListButtonsWidget::unsetIconRemoveButton()
  510. {
  511. Q_D(ctkPathListButtonsWidget);
  512. d->RemoveButton->setIcon(QIcon(":/Icons/minus.png"));
  513. }
  514. //-----------------------------------------------------------------------------
  515. void ctkPathListButtonsWidget::unsetIconEditButton()
  516. {
  517. Q_D(ctkPathListButtonsWidget);
  518. d->EditButton->setIcon(QIcon(":/Icons/edit.png"));
  519. }
  520. //-----------------------------------------------------------------------------
  521. bool ctkPathListButtonsWidget::isButtonsAutoRaise() const
  522. {
  523. Q_D(const ctkPathListButtonsWidget);
  524. return d->AddFilesButton->autoRaise();
  525. }
  526. //-----------------------------------------------------------------------------
  527. void ctkPathListButtonsWidget::setButtonsAutoRaise(bool autoRaise)
  528. {
  529. Q_D(ctkPathListButtonsWidget);
  530. d->AddFilesButton->setAutoRaise(autoRaise);
  531. d->AddDirectoryButton->setAutoRaise(autoRaise);
  532. d->RemoveButton->setAutoRaise(autoRaise);
  533. d->EditButton->setAutoRaise(autoRaise);
  534. }
  535. //-----------------------------------------------------------------------------
  536. int ctkPathListButtonsWidget::buttonSpacing() const
  537. {
  538. return this->layout()->spacing();
  539. }
  540. //-----------------------------------------------------------------------------
  541. void ctkPathListButtonsWidget::setButtonSpacing(int spacing)
  542. {
  543. this->layout()->setSpacing(spacing);
  544. }
  545. //-----------------------------------------------------------------------------
  546. Qt::Orientation ctkPathListButtonsWidget::orientation() const
  547. {
  548. return qobject_cast<QVBoxLayout*>(this->layout()) ? Qt::Vertical : Qt::Horizontal;
  549. }
  550. //-----------------------------------------------------------------------------
  551. void ctkPathListButtonsWidget::setOrientation(Qt::Orientation orientation)
  552. {
  553. QVBoxLayout* verticalLayout = qobject_cast<QVBoxLayout*>(this->layout());
  554. if (verticalLayout && orientation == Qt::Vertical)
  555. {
  556. return;
  557. }
  558. QLayout* oldLayout = this->layout();
  559. QLayout* newLayout = NULL;
  560. if (orientation == Qt::Vertical)
  561. {
  562. newLayout = new QVBoxLayout;
  563. }
  564. else
  565. {
  566. newLayout = new QHBoxLayout;
  567. }
  568. newLayout->setContentsMargins(0,0,0,0);
  569. newLayout->setSpacing(oldLayout->spacing());
  570. QLayoutItem* item = 0;
  571. while((item = oldLayout->takeAt(0)))
  572. {
  573. if (item->widget())
  574. {
  575. newLayout->addWidget(item->widget());
  576. }
  577. }
  578. delete oldLayout;
  579. this->setLayout(newLayout);
  580. }
  581. //-----------------------------------------------------------------------------
  582. QToolButton *ctkPathListButtonsWidget::buttonAddFiles() const
  583. {
  584. Q_D(const ctkPathListButtonsWidget);
  585. return d->AddFilesButton;
  586. }
  587. //-----------------------------------------------------------------------------
  588. QToolButton *ctkPathListButtonsWidget::buttonAddDirectory() const
  589. {
  590. Q_D(const ctkPathListButtonsWidget);
  591. return d->AddDirectoryButton;
  592. }
  593. //-----------------------------------------------------------------------------
  594. QToolButton *ctkPathListButtonsWidget::buttonEdit() const
  595. {
  596. Q_D(const ctkPathListButtonsWidget);
  597. return d->EditButton;
  598. }
  599. //-----------------------------------------------------------------------------
  600. QToolButton *ctkPathListButtonsWidget::buttonRemove() const
  601. {
  602. Q_D(const ctkPathListButtonsWidget);
  603. return d->RemoveButton;
  604. }