Subversion Repositories Scribus

Rev

Rev 24665 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
24706 jghali 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
24444 jghali 7
 
24706 jghali 8
#include <cstdlib>
9
 
10
#include <QDebug>
11
#include <QStandardPaths>
12
#include <QLayout>
13
#include <QLineEdit>
14
#include <QListView>
15
#include <QPushButton>
16
#include <QStringList>
17
#include <QUrl>
18
 
19
#include "filedialogeventcatcher.h"
20
#include "scfilewidget.h"
21
 
22
 
23
ScFileWidget::ScFileWidget(QWidget * parent) : QFileDialog(parent, Qt::Widget)
24
{
25
        setOption(QFileDialog::DontUseNativeDialog);
26
        setSizeGripEnabled(false);
27
        setModal(false);
28
        setViewMode(QFileDialog::List);
29
        setWindowFlags(Qt::Widget);
30
 
24444 jghali 31
        // The margins' content should be set both on the widget and its layout.
32
        setContentsMargins(0, 0, 0, 0);
24706 jghali 33
        layout()->setContentsMargins(0, 0, 0, 0);
24665 jghali 34
 
24706 jghali 35
#ifdef Q_OS_MAC
36
        QList<QUrl> urls;
37
        QUrl computer(QUrl::fromLocalFile(QLatin1String("")));
38
        if (!urls.contains(computer))
39
                urls << computer;
40
        QUrl volumes(QUrl::fromLocalFile("/Volumes"));
41
        if (!urls.contains(volumes))
42
                urls << volumes;
43
        QUrl dt(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)));
44
        if (!urls.contains(dt))
45
                urls << dt;
46
        setSidebarUrls(urls);
47
#endif
48
 
49
        FileDialogEventCatcher* keyCatcher = new FileDialogEventCatcher(this);
50
        QList<QListView *> childListViews = findChildren<QListView *>();
51
        for (QListView * lvi : childListViews)
52
                lvi->installEventFilter(keyCatcher);
53
        connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject()));
54
        connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString)));
55
        connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory()));
56
        connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory()));
57
        connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory()));
58
        connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory()));
59
 
60
        QList<QPushButton *> childPushButtons = findChildren<QPushButton *>();
61
        for (QPushButton* pb : childPushButtons)
62
                pb->setVisible(false);
63
        setMinimumSize(QSize(480, 310));
64
        setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
65
}
66
 
24665 jghali 67
void ScFileWidget::forceDoubleClickActivation(bool force)
68
{
69
        // Hack to make the previews in our file dialogs usable again,
70
        // needed e.g on OpenSuse KDE. Otherwise file would open on first
71
        // click, leaving user no time to see preview.
72
        if (m_forceDoubleClickActivation == force)
24706 jghali 73
                return;
74
 
75
        if (force)
76
                setStyleSheet(QStringLiteral("QAbstractItemView { activate-on-singleclick: 0; }"));
77
        else
78
                setStyleSheet(QString());
79
        m_forceDoubleClickActivation = force;
80
}
81
 
82
QString ScFileWidget::selectedFile()
83
{
84
        QStringList l(selectedFiles());
85
        if (l.count() == 0)
86
                return QString();
87
        return l.at(0);
88
}
89
 
90
void ScFileWidget::locationDropped(const QString& fileUrl)
91
{
92
        QFileInfo fi(fileUrl);
93
        if (fi.isDir())
94
        {
95
                setDirectory(fi.absoluteFilePath());
96
                return;
97
        }
98
 
99
        QString absFilePath = fi.absolutePath();
100
        QString fileName = fi.fileName();
101
 
102
        setDirectory(absFilePath);
103
        selectFile(fileName);
104
}
105
 
106
void ScFileWidget::gotoParentDirectory()
107
{
108
        QDir d(directory());
109
        d.cdUp();
110
        setDirectory(d);
111
}
112
 
113
void ScFileWidget::gotoSelectedDirectory()
114
{
115
        QStringList s(selectedFiles());
116
        if (!s.isEmpty())
117
        {
118
                QFileInfo fi(s.first());
119
//              qDebug()<<s.first()<<fi.absoluteFilePath();
120
                if (fi.isDir())
121
                        setDirectory(fi.absoluteFilePath());
122
        }
123
}
124
 
125
void ScFileWidget::gotoDesktopDirectory()
126
{
127
        QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
128
        QFileInfo fi(dp);
129
        if (fi.exists())
130
                setDirectory(dp);
131
}
132
 
133
void ScFileWidget::gotoHomeDirectory()
134
{
135
        QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
136
        QFileInfo fi(dp);
137
        if (fi.exists())
138
                setDirectory(dp);
139
}
140