⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3filedialog.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        ~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> {    public:        UrlInfoList() { setAutoDelete(true); }        int compareItems(Q3PtrCollection::Item n1, Q3PtrCollection::Item n2) {            if (!n1 || !n2)                return 0;            QUrlInfo *i1 = (QUrlInfo *)n1;            QUrlInfo *i2 = (QUrlInfo *)n2;            if (i1->isDir() && !i2->isDir())                return -1;            if (!i1->isDir() && i2->isDir())                return 1;            if (i1->name() == QLatin1String(".."))                return -1;            if (i2->name() == QLatin1String(".."))                return 1;            if (sortFilesBy == QDir::Name) {#if defined(Q_OS_WIN32)		QString name1 = i1->name().lower();		QString name2 = i2->name().lower();		return name1.localeAwareCompare( name2 );#else		QString name1 = i1->name();		QString name2 = i2->name();		return name1.localeAwareCompare( name2 );#endif            }            if (QUrlInfo::equal(*i1, *i2, sortFilesBy))                return 0;            else if (QUrlInfo::greaterThan(*i1, *i2, sortFilesBy))                return 1;            else if (QUrlInfo::lessThan(*i1, *i2, sortFilesBy))                return -1;            // can't happen...            return 0;        }        QUrlInfo *operator[](int i) {            return at(i);        }    };    UrlInfoList sortedList;    Q3PtrList<File> pendingItems;    QFileListBox * moreFiles;    Q3FileDialog::Mode mode;    QString rw;    QString ro;    QString wo;    QString inaccessible;    QString symLinkToFile;    QString file;    QString symLinkToDir;    QString dir;    QString symLinkToSpecial;    QString special;    Q3WidgetStack *preview;    bool infoPreview, contentsPreview;    QSplitter *splitter;    Q3UrlOperator url, oldUrl;    QWidget *infoPreviewWidget, *contentsPreviewWidget;    Q3FilePreview *infoPreviewer, *contentsPreviewer;    bool hadDotDot;    bool ignoreNextKeyPress;    // ignores the next refresh operation in case the user forced a selection    bool ignoreNextRefresh;    QFDProgressDialog *progressDia;    bool checkForFilter;    bool ignoreStop;    QTimer *mimeTypeTimer;    const Q3NetworkOperation *currListChildren;    // this is similar to QUrl::encode but does encode "*" and    // doesn't encode whitespaces    static QString encodeFileName(const QString& fName) {        QString newStr;        Q3CString cName = fName.utf8();        const Q3CString sChars(#ifdef Q_WS_WIN            "#%"#else            "<>#@\"&%$:,;?={}|^~[]\'`\\*"#endif           );        int len = cName.length();        if (!len)            return QString();        for (int i = 0; i < len ;++i) {            uchar inCh = (uchar)cName[i];            if (inCh >= 128 || sChars.contains(inCh))            {                newStr += QLatin1Char('%');                ushort c = inCh / 16;                c += c > 9 ? 'A' - 10 : '0';                newStr += QLatin1Char((char)c);                c = inCh % 16;                c += c > 9 ? 'A' - 10 : '0';                newStr += QLatin1Char((char)c);            } else {                newStr += QLatin1Char((char)inCh);            }        }        return newStr;    }    static bool fileExists(const Q3UrlOperator &url, const QString& name)    {        Q3Url u(url, Q3FileDialogPrivate::encodeFileName(name));        if (u.isLocalFile()) {            QFileInfo f(u.path());            return f.exists();        } else {            Q3NetworkProtocol *p = Q3NetworkProtocol::getNetworkProtocol(url.protocol());            if (p && (p->supportedOperations()&Q3NetworkProtocol::OpListChildren)) {                QUrlInfo ui(url.info(name.isEmpty() ? QString::fromLatin1(".") : name));                return ui.isValid();            }        }        return true;    }#ifndef Q_NO_CURSOR    bool cursorOverride; // Remember if the cursor was overridden or not.#endif};Q3FileDialogPrivate::~Q3FileDialogPrivate(){    delete modeButtons;}/************************************************************************ * * Internal class QRenameEdit * ************************************************************************/void QRenameEdit::keyPressEvent(QKeyEvent *e){    if (e->key() == Qt::Key_Escape)        emit cancelRename();    else        QLineEdit::keyPressEvent(e);    e->accept();}void QRenameEdit::focusOutEvent(QFocusEvent *){    if (!doRenameAlreadyEmitted) {        doRenameAlreadyEmitted = true;        emit doRename();    }}void QRenameEdit::slotReturnPressed(){    doRenameAlreadyEmitted = true;    emit doRename();}/************************************************************************ * * Internal class QFileListBox * ************************************************************************/QFileListBox::QFileListBox(QWidget *parent, Q3FileDialog *dlg)    : Q3ListBox(parent, "filelistbox"), filedialog(dlg),      renaming(false), renameItem(0), mousePressed(false),      firstMousePressEvent(true){    changeDirTimer = new QTimer(this);    Q3VBox *box = new Q3VBox(viewport(), "qt_vbox");    box->setFrameStyle(QFrame::Box | QFrame::Plain);    lined = new QRenameEdit(box);    lined->setFixedHeight(lined->sizeHint().height());    box->hide();    box->setBackgroundRole(QPalette::Base);    renameTimer = new QTimer(this);    connect(lined, SIGNAL(doRename()),             this, SLOT (rename()));    connect(lined, SIGNAL(cancelRename()),             this, SLOT(cancelRename()));    connect(renameTimer, SIGNAL(timeout()),             this, SLOT(doubleClickTimeout()));    connect(changeDirTimer, SIGNAL(timeout()),             this, SLOT(changeDirDuringDrag()));    connect(this, SIGNAL(contentsMoving(int,int)),             this, SLOT(contentsMoved(int,int)));    viewport()->setAcceptDrops(true);    dragItem = 0;}void QFileListBox::show(){    setBackgroundRole(QPalette::Base);    viewport()->setBackgroundRole(QPalette::Base);    Q3ListBox::show();}void QFileListBox::keyPressEvent(QKeyEvent *e){    if ((e->key() == Qt::Key_Enter ||           e->key() == Qt::Key_Return) &&         renaming)        return;    QString keyPressed = ((QKeyEvent *)e)->text().toLower();    QChar keyChar = keyPressed[0];    if (keyChar.isLetterOrNumber()) {        Q3ListBoxItem * i = 0;        if (currentItem())        i = item(currentItem());        else        i = firstItem();        if (i->next())        i = i->next();        else        i = firstItem();        while (i != item(currentItem())) {            QString it = text(index(i));            if (it[0].toLower() == keyChar) {            clearSelection();            setCurrentItem(i);            } else {            if (i->next())            i = i->next();            else            i = firstItem();            }        }    }    cancelRename();    Q3ListBox::keyPressEvent(e);}void QFileListBox::viewportMousePressEvent(QMouseEvent *e){    pressPos = e->pos();    mousePressed = false;    bool didRename = renaming;    cancelRename();    if (!hasFocus() && !viewport()->hasFocus())        setFocus();    if (e->button() != Qt::LeftButton) {        Q3ListBox::viewportMousePressEvent(e);        firstMousePressEvent = false;        return;    }    int i = currentItem();    bool wasSelected = false;    if (i != -1)        wasSelected = item(i)->isSelected();    Q3ListBox::mousePressEvent(e);    Q3FileDialogPrivate::MCItem *i1 = (Q3FileDialogPrivate::MCItem*)item(currentItem());    if (i1)        mousePressed =  (!((Q3FileDialogPrivate::File*)i1->i)->info.isDir())                        || (filedialog->mode() == Q3FileDialog::Directory) || (filedialog->mode() == Q3FileDialog::DirectoryOnly);    if (itemAt(e->pos()) != item(i)) {        firstMousePressEvent = false;        return;    }     if (!firstMousePressEvent && !didRename && i == currentItem() && currentItem() != -1 &&          wasSelected && QUrlInfo(filedialog->d->url.info(QString(QLatin1Char('.')))).isWritable() && item(currentItem())->text() != QLatin1String("..")) {        renameTimer->start(QApplication::doubleClickInterval(), true);        renameItem = item(i);    }    firstMousePressEvent = false;}void QFileListBox::viewportMouseReleaseEvent(QMouseEvent *e){    dragItem = 0;    Q3ListBox::viewportMouseReleaseEvent(e);    mousePressed = false;}void QFileListBox::viewportMouseDoubleClickEvent(QMouseEvent *e){    renameTimer->stop();    Q3ListBox::viewportMouseDoubleClickEvent(e);}void QFileListBox::viewportMouseMoveEvent(QMouseEvent *e){    if (!dragItem)        dragItem = itemAt(e->pos());    renameTimer->stop();#ifndef QT_NO_DRAGANDDROP    if ( (pressPos - e->pos()).manhattanLength() > QApplication::startDragDistance() && mousePressed) {        Q3ListBoxItem *item = dragItem;        dragItem = 0;        if (item) {            if (!itemRect(item).contains(e->pos()))                return;            Q3UriDrag* drag = new Q3UriDrag(viewport());            QStringList files;            if (filedialog->mode() == Q3FileDialog::ExistingFiles)                files = filedialog->selectedFiles();            else                files = QStringList(filedialog->selectedFile());            drag->setFileNames(files);            if (lined->parentWidget()->isVisible())                cancelRename();            connect(drag, SIGNAL(destroyed()),                     this, SLOT(dragObjDestroyed()));            drag->drag();            mousePressed = false;        }    } else#endif    {        Q3ListBox::viewportMouseMoveEvent(e);    }}void QFileListBox::dragObjDestroyed(){#ifndef QT_NO_DRAGANDDROP    //#######    //filedialog->rereadDir();#endif}#ifndef QT_NO_DRAGANDDROPvoid QFileListBox::viewportDragEnterEvent(QDragEnterEvent *e){    startDragUrl = filedialog->d->url;    startDragDir = filedialog->dirPath();    currDropItem = 0;    if (!Q3UriDrag::canDecode(e)) {        e->ignore();        return;    }    QStringList l;    Q3UriDrag::decodeLocalFiles(e, l);    urls = (int)l.count();    if (acceptDrop(e->pos(), e->source())) {        e->accept();        setCurrentDropItem(e->pos());    } else {        e->ignore();        setCurrentDropItem(QPoint(-1, -1));    }    oldDragPos = e->pos();}void QFileListBox::viewportDragMoveEvent(QDragMoveEvent *e){    if (acceptDrop(e->pos(), e->source())) {        switch (e->action()) {        case QDropEvent::Copy:            e->acceptAction();            break;        case QDropEvent::Move:            e->acceptAction();            break;        case QDropEvent::Link:            break;        default:            break;        }        if (oldDragPos != e->pos())            setCurrentDropItem(e->pos());    } else {        changeDirTimer->stop();        e->ignore();        setCurrentDropItem(QPoint(-1, -1));    }    oldDragPos = e->pos();}void QFileListBox::viewportDragLeaveEvent(QDragLeaveEvent *){    changeDirTimer->stop();    setCurrentDropItem(QPoint(-1, -1));//########//     if (startDragDir != filedialog->d->url)//        filedialog->setUrl(startDragUrl);}void QFileListBox::viewportDropEvent(QDropEvent *e){    changeDirTimer->stop();    if (!Q3UriDrag::canDecode(e)) {        e->ignore();        return;    }    Q3StrList l;    Q3UriDrag::decode(e, l);    bool move = e->action() == QDropEvent::Move;//     bool supportAction = move || e->action() == QDropEvent::Copy;    Q3UrlOperator dest;    if (currDropItem)        dest = Q3UrlOperator(filedialog->d->url, Q3FileDialogPrivate::encodeFileName(currDropItem->text()));    else        dest = filedialog->d->url;    QStringList lst;    for (uint i = 0; i < l.count(); ++i) {        lst << QLatin1String(l.at(i));    }    filedialog->d->url.copy(lst, dest, move);    // ##### what is supportAction for?    e->acceptAction();    currDropItem = 0;}bool QFileListBox::acceptDrop(const QPoint &pnt, QWidget *source){    Q3ListBoxItem *item = itemAt(pnt);    if (!item || item && !itemRect(item).contains(pnt)) {        if (source == viewport() && startDragDir == filedialog->dirPath())            return false;        return true;    }    QUrlInfo fi(filedialog->d->url.info(item->text().isEmpty() ? QString::fromLatin1(".") : item->text()));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -