📄 q3filedialog.cpp
字号:
lastWidth = that->width() - extWidth; lastHeight = that->height() - extHeight;}// Don't remove the lines below!//// resolving the W methods manually is needed, because Windows 95 doesn't include// these methods in Shell32.lib (not even stubs!), so you'd get an unresolved symbol// when Qt calls getEsistingDirectory(), etc.#if defined(Q_WS_WIN)typedef UINT (WINAPI *PtrExtractIconEx)(LPCTSTR,int,HICON*,HICON*,UINT);static PtrExtractIconEx ptrExtractIconEx = 0;static void resolveLibs(){#ifndef Q_OS_TEMP static bool triedResolve = false; if (!triedResolve) {#ifndef QT_NO_THREAD // protect initialization QMutexLocker locker(qt_global_mutexpool ? qt_global_mutexpool->get(&triedResolve) : 0); // check triedResolve again, since another thread may have already // done the initialization if (triedResolve) { // another thread did initialize the security function pointers, // so we shouldn't do it again. return; }#endif triedResolve = true; if (qt_winUnicode()) { QLibrary lib("shell32"); ptrExtractIconEx = (PtrExtractIconEx) lib.resolve("ExtractIconExW"); } }#endif}#ifdef Q_OS_TEMP#define PtrExtractIconEx ExtractIconEx#endifclass QWindowsIconProvider : public Q3FileIconProvider{public: QWindowsIconProvider(QObject *parent=0, const char *name=0); ~QWindowsIconProvider(); const QPixmap * pixmap(const QFileInfo &fi);private: QPixmap defaultFolder; QPixmap defaultFile; QPixmap defaultExe; QPixmap pix; int pixw, pixh; QMap< QString, QPixmap > cache;};#endifstatic void makeVariables() { if (!openFolderIcon) { workingDirectory = new QString(::toRootIfNotExists( QDir::currentDirPath() )); qfd_cleanup_string.add(&workingDirectory); openFolderIcon = new QPixmap((const char **)open_xpm); qfd_cleanup_pixmap.add(&openFolderIcon); symLinkDirIcon = new QPixmap((const char **)link_dir_xpm); qfd_cleanup_pixmap.add(&symLinkDirIcon); symLinkFileIcon = new QPixmap((const char **)link_file_xpm); qfd_cleanup_pixmap.add(&symLinkFileIcon); fileIcon = new QPixmap((const char **)file_xpm); qfd_cleanup_pixmap.add(&fileIcon); closedFolderIcon = new QPixmap((const char **)closed_xpm); qfd_cleanup_pixmap.add(&closedFolderIcon); detailViewIcon = new QPixmap((const char **)detailedview_xpm); qfd_cleanup_pixmap.add(&detailViewIcon); multiColumnListViewIcon = new QPixmap((const char **)mclistview_xpm); qfd_cleanup_pixmap.add(&multiColumnListViewIcon); cdToParentIcon = new QPixmap((const char **)cdtoparent_xpm); qfd_cleanup_pixmap.add(&cdToParentIcon); newFolderIcon = new QPixmap((const char **)newfolder_xpm); qfd_cleanup_pixmap.add(&newFolderIcon); previewInfoViewIcon = new QPixmap((const char **)previewinfoview_xpm); qfd_cleanup_pixmap.add(&previewInfoViewIcon); previewContentsViewIcon = new QPixmap((const char **)previewcontentsview_xpm); qfd_cleanup_pixmap.add(&previewContentsViewIcon); startCopyIcon = new QPixmap((const char **)start_xpm); qfd_cleanup_pixmap.add(&startCopyIcon); endCopyIcon = new QPixmap((const char **)end_xpm); qfd_cleanup_pixmap.add(&endCopyIcon); goBackIcon = new QPixmap((const char **)back_xpm); qfd_cleanup_pixmap.add(&goBackIcon); fifteenTransparentPixels = new QPixmap(closedFolderIcon->width(), 1); qfd_cleanup_pixmap.add(&fifteenTransparentPixels); QBitmap m(fifteenTransparentPixels->width(), 1); m.fill(Qt::color0); fifteenTransparentPixels->setMask(m); bShowHiddenFiles = false; sortFilesBy = (int)QDir::Name; detailViewMode = false;#if defined(Q_WS_WIN) if (!fileIconProvider) fileIconProvider = new QWindowsIconProvider(qApp);#endif }}/****************************************************************** * * Definitions of view classes * ******************************************************************/class QRenameEdit : public QLineEdit{ Q_OBJECTpublic: QRenameEdit(QWidget *parent);protected: void keyPressEvent(QKeyEvent *e); void focusOutEvent(QFocusEvent *e);signals: void cancelRename(); void doRename();private slots: void slotReturnPressed();private: bool doRenameAlreadyEmitted;};QRenameEdit::QRenameEdit(QWidget *parent) : QLineEdit(parent, "qt_rename_edit"), doRenameAlreadyEmitted(false){ connect(this, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));}class QFileListBox : public Q3ListBox{ friend class Q3FileDialog; Q_OBJECTprivate: QFileListBox(QWidget *parent, Q3FileDialog *d); void clear(); void show(); void startRename(bool check = true); void viewportMousePressEvent(QMouseEvent *e); void viewportMouseReleaseEvent(QMouseEvent *e); void viewportMouseDoubleClickEvent(QMouseEvent *e); void viewportMouseMoveEvent(QMouseEvent *e);#ifndef QT_NO_DRAGANDDROP void viewportDragEnterEvent(QDragEnterEvent *e); void viewportDragMoveEvent(QDragMoveEvent *e); void viewportDragLeaveEvent(QDragLeaveEvent *e); void viewportDropEvent(QDropEvent *e); bool acceptDrop(const QPoint &pnt, QWidget *source); void setCurrentDropItem(const QPoint &pnt);#endif void keyPressEvent(QKeyEvent *e);private slots: void rename(); void cancelRename(); void doubleClickTimeout(); void changeDirDuringDrag(); void dragObjDestroyed(); void contentsMoved(int, int);private: QRenameEdit *lined; Q3FileDialog *filedialog; bool renaming; QTimer* renameTimer; Q3ListBoxItem *renameItem, *dragItem; QPoint pressPos, oldDragPos; bool mousePressed; int urls; QString startDragDir; Q3ListBoxItem *currDropItem; QTimer *changeDirTimer; bool firstMousePressEvent; Q3UrlOperator startDragUrl;};class Q3FileDialogQFileListView : public Q3ListView{ Q_OBJECTpublic: Q3FileDialogQFileListView(QWidget *parent, Q3FileDialog *d); void clear(); void startRename(bool check = true); void setSorting(int column, bool increasing = true); QRenameEdit *lined; bool renaming; Q3ListViewItem *renameItem;private: void viewportMousePressEvent(QMouseEvent *e); void viewportMouseDoubleClickEvent(QMouseEvent *e); void keyPressEvent(QKeyEvent *e); void viewportMouseReleaseEvent(QMouseEvent *e); void viewportMouseMoveEvent(QMouseEvent *e);#ifndef QT_NO_DRAGANDDROP void viewportDragEnterEvent(QDragEnterEvent *e); void viewportDragMoveEvent(QDragMoveEvent *e); void viewportDragLeaveEvent(QDragLeaveEvent *e); void viewportDropEvent(QDropEvent *e); bool acceptDrop(const QPoint &pnt, QWidget *source); void setCurrentDropItem(const QPoint &pnt);#endifprivate slots: void rename(); void cancelRename(); void changeSortColumn2(int column); void doubleClickTimeout(); void changeDirDuringDrag(); void dragObjDestroyed(); void contentsMoved(int, int);private: Q3FileDialog *filedialog; QTimer* renameTimer; QPoint pressPos, oldDragPos; bool mousePressed; int urls; QString startDragDir; Q3ListViewItem *currDropItem, *dragItem; QTimer *changeDirTimer; bool firstMousePressEvent; bool ascending; int sortcolumn; Q3UrlOperator startDragUrl;};/**************************************************************************** * * Classes for copy progress dialog * ****************************************************************************/class QFDProgressAnimation : public QWidget{ Q_OBJECTpublic: QFDProgressAnimation(QWidget *parent); void start();private slots: void next();protected: void paintEvent(QPaintEvent *e);private: int step; QTimer *timer;};QFDProgressAnimation::QFDProgressAnimation(QWidget *parent) : QWidget(parent, "qt_progressanimation"){ setFixedSize(300, 50); step = -1; next(); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(next()));}void QFDProgressAnimation::start(){ timer->start(150, false);}void QFDProgressAnimation::next(){ ++step; if (step > 10) step = 0; repaint();}void QFDProgressAnimation::paintEvent(QPaintEvent *){ erase(); QPainter p; p.begin(this); if (step == 0) { p.drawPixmap(5, (height() - startCopyIcon->height()) / 2, *startCopyIcon); p.drawPixmap(width() - 5 - openFolderIcon->width(), (height() - openFolderIcon->height()) / 2 , *openFolderIcon); } else if (step == 10) { p.drawPixmap(5, (height() - openFolderIcon->height()) / 2, *openFolderIcon); p.drawPixmap(width() - 5 - endCopyIcon->width(), (height() - endCopyIcon->height()) / 2 , *endCopyIcon); } else { p.drawPixmap(5, (height() - openFolderIcon->height()) / 2, *openFolderIcon); p.drawPixmap(width() - 5 - openFolderIcon->width(), (height() - openFolderIcon->height()) / 2 , *openFolderIcon); int x = 10 + openFolderIcon->width(); int w = width() - 2 * x; int s = w / 9; p.drawPixmap(x + s * step, (height() - fileIcon->height()) / 2 - fileIcon->height(), *fileIcon); }}class QFDProgressDialog : public QDialog{ Q_OBJECTpublic: QFDProgressDialog(QWidget *parent, const QString &fn, int steps); void setReadProgress(int p); void setWriteProgress(int p); void setWriteLabel(const QString &s);signals: void cancelled();private: Q3ProgressBar *readBar; Q3ProgressBar *writeBar; QLabel *writeLabel; QFDProgressAnimation *animation;};QFDProgressDialog::QFDProgressDialog(QWidget *parent, const QString &fn, int steps) : QDialog(parent, "", true){ setWindowTitle(Q3FileDialog::tr("Copy or Move a File")); QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(5); layout->setMargin(5); animation = new QFDProgressAnimation(this); layout->addWidget(animation); layout->addWidget(new QLabel(Q3FileDialog::tr("Read: %1").arg(fn), this, "qt_read_lbl")); readBar = new Q3ProgressBar(steps, this, "qt_readbar"); readBar->reset(); readBar->setProgress(0); layout->addWidget(readBar); writeLabel = new QLabel(Q3FileDialog::tr("Write: %1").arg(QString()), this, "qt_write_lbl"); layout->addWidget(writeLabel); writeBar = new Q3ProgressBar(steps, this, "qt_writebar"); writeBar->reset(); writeBar->setProgress(0); layout->addWidget(writeBar); QPushButton *b = new QPushButton(Q3FileDialog::tr("Cancel"), this, "qt_cancel_btn"); b->setFixedSize(b->sizeHint()); layout->addWidget(b); connect(b, SIGNAL(clicked()), this, SIGNAL(cancelled())); animation->start();}void QFDProgressDialog::setReadProgress(int p){ readBar->setProgress(p);}void QFDProgressDialog::setWriteProgress(int p){ writeBar->setProgress(p);}void QFDProgressDialog::setWriteLabel(const QString &s){ writeLabel->setText(Q3FileDialog::tr("Write: %1").arg(s));}/************************************************************************ * * Private Q3FileDialog members * ************************************************************************/class Q3FileDialogPrivate {public: ~Q3FileDialogPrivate(); QStringList history; bool geometryDirty; Q3ComboBox * paths; QComboBox * types; QLabel * pathL; QLabel * fileL; QLabel * typeL; QVBoxLayout * topLevelLayout; QHBoxLayout *buttonLayout, *leftLayout, *rightLayout; Q3PtrList<QHBoxLayout> extraWidgetsLayouts; Q3PtrList<QLabel> extraLabels; Q3PtrList<QWidget> extraWidgets; Q3PtrList<QWidget> extraButtons; Q3PtrList<QAbstractButton> toolButtons; Q3WidgetStack * stack; QToolButton * cdToParent, *newFolder, * detailView, * mcView, *previewInfo, *previewContents, *goBack; Q3ButtonGroup * modeButtons; QString currentFileName; Q3ListViewItem *last; Q3ListBoxItem *lastEFSelected; struct File: public Q3ListViewItem { File(Q3FileDialogPrivate * dlgp, const QUrlInfo * fi, Q3ListViewItem * parent) : Q3ListViewItem(parent, dlgp->last), info(*fi), d(dlgp), i(0), hasMimePixmap(false) { setup(); dlgp->last = this; } File(Q3FileDialogPrivate * dlgp, const QUrlInfo * fi, Q3ListView * parent) : Q3ListViewItem(parent, dlgp->last), info(*fi), d(dlgp), i(0), hasMimePixmap(false) { setup(); dlgp->last = this; } File(Q3FileDialogPrivate * dlgp, const QUrlInfo * fi, Q3ListView * parent, Q3ListViewItem * after) : Q3ListViewItem(parent, after), info(*fi), d(dlgp), i(0), hasMimePixmap(false) { setup(); if (!nextSibling()) dlgp->last = this; } ~File(); QString text(int column) const; const QPixmap * pixmap(int) const; QUrlInfo info; Q3FileDialogPrivate * d; Q3ListBoxItem *i; bool hasMimePixmap; }; class MCItem: public Q3ListBoxItem { public: MCItem(Q3ListBox *, Q3ListViewItem * item); MCItem(Q3ListBox *, Q3ListViewItem * item, Q3ListBoxItem *after); QString text() const; const QPixmap *pixmap() const; int height(const Q3ListBox *) const; int width(const Q3ListBox *) const; void paint(QPainter *); Q3ListViewItem * i; }; class UrlInfoList : public Q3PtrList<QUrlInfo> {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -