Skip to content

Commit

Permalink
feat: add setFileMode/fileMode to dfilechooseredit
Browse files Browse the repository at this point in the history
Change-Id: I8c22a3a44fbab3f6f3b1345eee3bdd566dc285da
  • Loading branch information
Iceyer committed Dec 21, 2017
1 parent 7033673 commit 770c8a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/widgets/dfilechooseredit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ void DFileChooserEdit::setDialogDisplayPosition(DFileChooserEdit::DialogDisplayP
d->dialogDisplayPosition = dialogDisplayPosition;
}


void DFileChooserEdit::setFileMode(QFileDialog::FileMode mode)
{
D_D(DFileChooserEdit);
d->fileMode = mode;
}

QFileDialog::FileMode DFileChooserEdit::fileMode() const
{
D_DC(DFileChooserEdit);
return d->fileMode;
}

DFileChooserEditPrivate::DFileChooserEditPrivate(DFileChooserEdit *q)
: DLineEditPrivate(q)
{
Expand All @@ -58,7 +71,7 @@ void DFileChooserEditPrivate::init()
{
D_Q(DFileChooserEdit);

q->setTextMargins(0, 0, 16, 0);
q->setTextMargins(0, 0, 24, 0);
q->setReadOnly(true);
q->setIconVisible(true);
q->connect(q, SIGNAL(iconClicked()), q, SLOT(_q_showFileChooserDialog()));
Expand All @@ -71,13 +84,13 @@ void DFileChooserEditPrivate::_q_showFileChooserDialog()
QFileDialog dialog(q);

dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setFileMode(fileMode);

if(dialogDisplayPosition == DFileChooserEdit::CurrentMonitorCenter) {
if (dialogDisplayPosition == DFileChooserEdit::CurrentMonitorCenter) {
QPoint pos = QCursor::pos();

for(QScreen *screen : qApp->screens()) {
if(screen->geometry().contains(pos)) {
for (QScreen *screen : qApp->screens()) {
if (screen->geometry().contains(pos)) {
QRect rect = dialog.geometry();
rect.moveCenter(screen->geometry().center());
dialog.move(rect.topLeft());
Expand All @@ -90,7 +103,7 @@ void DFileChooserEditPrivate::_q_showFileChooserDialog()
int code = dialog.exec();


if(code == QDialog::Accepted && !dialog.selectedFiles().isEmpty()) {
if (code == QDialog::Accepted && !dialog.selectedFiles().isEmpty()) {
const QString fileName = dialog.selectedFiles().first();

q->setText(fileName);
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/dfilechooseredit.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define DFILECHOOSEREDIT_H

#include "dlineedit.h"
#include <QFileDialog>

DWIDGET_BEGIN_NAMESPACE

Expand All @@ -41,6 +42,9 @@ class LIBDTKWIDGETSHARED_EXPORT DFileChooserEdit : public DLineEdit

DialogDisplayPosition dialogDisplayPosition() const;

void setFileMode(QFileDialog::FileMode mode);
QFileDialog::FileMode fileMode() const;

public Q_SLOTS:
void setDialogDisplayPosition(DialogDisplayPosition dialogDisplayPosition);

Expand Down
1 change: 1 addition & 0 deletions src/widgets/private/dfilechooseredit_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DFileChooserEditPrivate : DLineEditPrivate
void _q_showFileChooserDialog();

DFileChooserEdit::DialogDisplayPosition dialogDisplayPosition = DFileChooserEdit::FoloowParentWindow;
QFileDialog::FileMode fileMode = QFileDialog::ExistingFile;
};

DWIDGET_END_NAMESPACE
Expand Down

0 comments on commit 770c8a8

Please sign in to comment.