QVariant FileObjectModel::data(const QModelIndex &index, int role) const { if(!mFileService) { return QVariant(); } if(!index.isValid()) { return QVariant(); } if(role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::DecorationRole) { return QVariant(); } FileObject *obj = (FileObject*)index.internalPointer(); if(role == Qt::DecorationRole) { QProxyStyle s; QIcon icon = obj->isDirectory() ? s.standardIcon(QStyle::SP_DirIcon) : s.standardIcon(QStyle::SP_FileIcon); return QVariant::fromValue(icon); } switch(index.column()) { case 0: return obj->name(); case 1: return obj->path(); case 2: return obj->size(); case 3: return obj->isDirectory(); } return QVariant(); }
bool AbstractStyleElementModel::isMainStyle() const { QStyle *style = qApp->style(); forever { if (style == m_style) return true; QProxyStyle *proxy = qobject_cast<QProxyStyle*>(style); if (!proxy) return false; style = proxy->baseStyle(); } }
QxFileBrowser::QxFileBrowser(QWidget* parent) : QWidget(parent), gotoMenu_(0), recentMenu_(0), showHidden_(false), showDetails_(true), createFileDialog_(0), createDirDialog_(0), renameDialog_(0) { //-------------------------------------------------------------------------- // setup primary model and view cwdModel_ = new QFileSystemModel(this); cwdModel_->setReadOnly(false); QModelIndex root = cwdModel_->setRootPath(QDir::currentPath()); connect( cwdModel_, SIGNAL(fileRenamed(const QString&, const QString&, const QString&)), this, SLOT(fileRenamed(const QString&, const QString&, const QString&)) ); dirView_ = new QxFileSystemView(this); dirView_->setModel(cwdModel_); dirView_->header()->hide(); dirView_->setRootIndex(root); dirView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); dirView_->setDragDropMode(QAbstractItemView::DragOnly); connect(dirView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(cwdSet(const QModelIndex&))); connect(dirView_, SIGNAL(escape()), this, SIGNAL(escape())); connect(dirView_, SIGNAL(cdUp()), this, SLOT(cdUp())); connect(cwdModel_, SIGNAL(layoutChanged()), dirView_, SLOT(resizeColumnsToContents())); setFocusProxy(dirView_); // dirView_->setTextElideMode(Qt::ElideMiddle); dirView_->setFrameStyle(QFrame::NoFrame); // dirView_->setIndentation(18); // together with a branch pixmap could improve branch alignment dirView_->setLineWidth(0); dirView_->setMidLineWidth(0); #ifdef Q_WS_MAC dirView_->setStyleSheet( "QTreeView {" " font-size: 12px;" "}" "QTreeView::item {" " padding-top: 1px;" "}" ); #endif { QPalette pal = dirView_->palette(); pal.setColor(QPalette::Base, styleManager()->color("fileBrowserDirViewBgColor")); dirView_->setPalette(pal); } //-------------------------------------------------------------------------- // setup navigation bar / panel head gotoButton_ = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserGotoButton"))); gotoButton_->setMode(QxControl::MenuMode); gotoButton_->visual()->setText(QDir::current().dirName()); gotoButton_->setMinimumWidth(10); // design HACK gotoButton_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); { QPixmap folderIcon = QFileIconProvider().icon(QFileInfo(QDir::currentPath())).pixmap(QSize(16, 16)); gotoButton_->visual()->setLeadingIcon(folderIcon); } #ifdef Q_WS_MAC #ifdef QT_MAC_USE_COCOA connect(gotoButton_, SIGNAL(toggled(bool)), this, SLOT(blockFloating(bool))); #endif // QT_MAC_USE_COCOA #endif // Q_WS_MAC updateGotoMenu(); class QxCdUpButton: public QxControl { public: QxCdUpButton(QWidget* parent) : QxControl(parent, new QxVisual(styleManager()->style("fileBrowserCdUpButton"))) {} private: // workaround HACK, prevent undocking, map double click event to single click virtual void mouseDoubleClickEvent(QMouseEvent* event) { press(); event->accept(); } }; QxControl* cdUpButton = new QxCdUpButton(this); cdUpButton->setMode(QxControl::TouchMode); connect(cdUpButton, SIGNAL(pressed()), this, SLOT(cdUp())); //-------------------------------------------------------------------------- // define context actions contextMenu_ = new QMenu(this); // QxDesignHack::beautify(contextMenu_); openDefaultAction_ = new QAction(tr("Open in Default App."), this); openDefaultAction_->setShortcut(tr("Ctrl+D")); openDefaultAction_->setShortcutContext(Qt::WidgetShortcut); openFileAction_ = new QAction(tr("Open in %1").arg(qApp->applicationName()), this); createFileAction_ = contextMenu_->addAction(tr("New File")); createDirAction_ = contextMenu_->addAction(tr("New Folder")); contextMenu_->addSeparator(); contextMenu_->addAction(openFileAction_); contextMenu_->addAction(openDefaultAction_); contextMenu_->addSeparator(); renameAction_ = contextMenu_->addAction(tr("Rename")); deleteAction_ = contextMenu_->addAction(tr("Move To Trash")); contextMenu_->addSeparator(); bookmarkAction_ = contextMenu_->addAction(tr("Bookmark")); contextMenu_->addSeparator(); showHiddenAction_ = contextMenu_->addAction(tr("Show Hidden")); showDetailsAction_ = contextMenu_->addAction(tr("Show Details")); connect(createFileAction_, SIGNAL(triggered()), this, SLOT(createFile())); connect(createDirAction_, SIGNAL(triggered()), this, SLOT(createDir())); connect(openDefaultAction_, SIGNAL(triggered()), this, SLOT(openDefault())); connect(openFileAction_, SIGNAL(triggered()), this, SLOT(openFile())); connect(renameAction_, SIGNAL(triggered()), this, SLOT(rename())); connect(deleteAction_, SIGNAL(triggered()), this, SLOT(delete_())); connect(dirView_, SIGNAL(delKeyPressed()), this, SLOT(delete_())); connect(showHiddenAction_, SIGNAL(toggled(bool)), this, SLOT(showHidden(bool))); connect(showDetailsAction_, SIGNAL(toggled(bool)), this, SLOT(showDetails(bool))); connect(bookmarkAction_, SIGNAL(triggered()), this, SLOT(bookmark())); showHiddenAction_->setCheckable(true); showDetailsAction_->setCheckable(true); showHiddenAction_->setChecked(false); showDetailsAction_->setChecked(false); //-------------------------------------------------------------------------- // setup toolbar QxControl* plusButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserPlusButton"))); plusButton->setMode(QxControl::TouchMode); connect(plusButton, SIGNAL(pressed()), this, SLOT(createFile())); QxControl* wheelButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserWheelButton"))); wheelButton->setMenu(contextMenu_); wheelButton->setMenuPopupMode(QxControl::DownsideMenuPopup|QxControl::UpsideMenuPopup|QxControl::PreferUpsideMenuPopup); QxControl* recentButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserRecentButton"))); recentButton->setMode(QxControl::TouchMode); connect(recentButton, SIGNAL(pressed()), this, SLOT(recentShowOrHide())); QxControl* bookmarksButton = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserBookmarksButton"))); bookmarksButton->setMode(QxControl::TouchMode); connect(bookmarksButton, SIGNAL(pressed()), this, SLOT(bookmarksShowOrHide())); statusBar_ = new QxStatusBar(this); showHidden(false); showDetails(false); //-------------------------------------------------------------------------- // setup bottom views recentModel_ = new QxUrlListModel(this); recentView_ = new QxUrlListView(this); // recentView_->header()->hide(); // recentView_->setViewMode(QListView::IconMode); // recentView_->setIconSize(QSize(16, 16)); recentView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); recentView_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); recentView_->setTextElideMode(Qt::ElideLeft); recentView_->setFrameStyle(QFrame::NoFrame); recentView_->setLineWidth(0); recentView_->setMidLineWidth(0); recentView_->setStyleSheet( "QListView::item {" " padding-top: 1px;" "}" ); // recentView_->setAlternatingRowColors(true); recentView_->setModel(recentModel_); connect(recentView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(gotoRecent(const QModelIndex&))); recentContextMenu_ = new QMenu(this); recentContextMenu_->addAction(tr("Goto"), this, SLOT(gotoRecent())); recentContextMenu_->addAction(tr("Add To Bookmarks"), this, SLOT(recentAddToBookmarks())); bookmarksModel_ = new QxUrlListModel(this); bookmarksModel_->setPathReduction(1); bookmarksView_ = new QxUrlListView(this); bookmarksView_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); bookmarksView_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); bookmarksView_->setTextElideMode(Qt::ElideLeft); bookmarksView_->setFrameStyle(QFrame::NoFrame); bookmarksView_->setLineWidth(0); bookmarksView_->setMidLineWidth(0); bookmarksView_->setStyleSheet( "QListView::item {" " padding-top: 1px;" "}" ); bookmarksView_->setModel(bookmarksModel_); bookmarksView_->setDragDropMode(QAbstractItemView::InternalMove); bookmarksView_->setDragEnabled(true); bookmarksView_->setAcceptDrops(true); bookmarksView_->setDropIndicatorShown(true); connect(bookmarksView_, SIGNAL(activated(const QModelIndex&)), this, SLOT(gotoBookmark(const QModelIndex&))); bookmarksContextMenu_ = new QMenu(this); bookmarksContextMenu_->addAction(tr("Add Current Directory"), this, SLOT(cwdAddToBookmark())); bookmarksContextMenu_->addAction(tr("Add Other Directory"), this, SLOT(addDirBookmark())); bookmarksContextMenu_->addSeparator(); bookmarksContextMenu_->addAction(tr("Goto Here"), this, SLOT(gotoBookmark())); bookmarksContextMenu_->addAction(tr("Remove From List"), this, SLOT(removeBookmark())); bookmarksContextMenu_->addSeparator(); bookmarksShowFullPathAction_ = bookmarksContextMenu_->addAction(tr("Show Full Path")); bookmarksShowFullPathAction_->setCheckable(true); bookmarksShowFullPathAction_->setChecked(bookmarksModel_->pathReduction() == -1); connect(bookmarksShowFullPathAction_, SIGNAL(toggled(bool)), this, SLOT(bookmarksShowFullPath(bool))); #ifdef Q_WS_MAC { QProxyStyle* proxyStyle = qobject_cast<QProxyStyle*>(style()); QMacStyle* macStyle = qobject_cast<QMacStyle*>((proxyStyle) ? proxyStyle->baseStyle() : style()); if (macStyle) { macStyle->setFocusRectPolicy(dirView_, QMacStyle::FocusDisabled); macStyle->setFocusRectPolicy(recentView_, QMacStyle::FocusDisabled); macStyle->setFocusRectPolicy(dirView_, QMacStyle::FocusDisabled); macStyle->setFocusRectPolicy(bookmarksView_, QMacStyle::FocusDisabled); } } #endif //-------------------------------------------------------------------------- // layout widgets handle_ = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserSplitter"))); handle_->visual()->setText(""); handleTextRecent_ = tr("Recent Places"); handleTextBookmarks_ = tr("Bookmarks"); bottomStack_ = new QxControl(this); bottomStackLayout_ = new QStackedLayout; bottomStackLayout_->addWidget(recentView_); bottomStackLayout_->addWidget(bookmarksView_); bottomStack_->setLayout(bottomStackLayout_); bottomStack_->setVisible(false); splitter_ = new QxSplitter(this); splitter_->setOrientation(Qt::Vertical); splitter_->setHandle(1, handle_); splitter_->setHandleWidth(styleManager()->constant("fileBrowserSplitterWidth")); splitter_->addWidget(dirView_); /*{ QxControl* carrier = new QxControl(this, new QxVisual(styleManager()->style("fileBrowserDirView"))); QGridLayout* layout = new QGridLayout; layout->setSpacing(0); layout->setMargin(0); layout->addWidget(dirView_); carrier->setLayout(layout); splitter_->addWidget(carrier); }*/ splitter_->addWidget(bottomStack_); // make dirView_ grow/shrink dynamically, while bottomStack_ keeps user-defined size splitter_->setStretchFactor(0, 1); splitter_->setStretchFactor(1, 0); QDockWidget* dock = qobject_cast<QDockWidget*>(parent); if (dock) { dock->setWidget(this); // connect(dock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(adaptToDockLocation(Qt::DockWidgetArea))); } QVBoxLayout* col = new QVBoxLayout; col->setSpacing(0); col->setMargin(0); { QxControl* carrier = new QxControl(parent, new QxVisual(styleManager()->style("fileBrowserNavCarrier"))); QHBoxLayout* row = new QHBoxLayout; row->setSpacing(0); row->setMargin(0); row->addWidget(gotoButton_); row->addStretch(); row->addWidget(cdUpButton); carrier->setLayout(row); if (dock) dock->setTitleBarWidget(carrier); else col->addWidget(carrier); } col->addWidget(splitter_); col->addWidget(styleManager()->hl(this)); { QBoxLayout* row = new QBoxLayout(QBoxLayout::LeftToRight); row->setSpacing(0); row->setMargin(0); row->addWidget(plusButton); row->addWidget(styleManager()->vl(this)); row->addWidget(wheelButton); row->addWidget(styleManager()->vl(this)); row->addWidget(recentButton); row->addWidget(styleManager()->vl(this)); row->addWidget(bookmarksButton); row->addWidget(styleManager()->vl(this)); row->addWidget(statusBar_); col->addLayout(row); bottomToolLayout_ = row; } setLayout(col); }
void cListWidget::navigate_to_our_folder() { //deleting old widgets this->clear(); //adding new widgets //adding folders QDir d( this->absolute_path ); QStringList eees = d.entryList( QDir::Dirs, QDir::Name ); for ( int i = 0; i < eees.count(); i++ ) { QListWidgetItem* it = new QListWidgetItem( eees.at(i) ); it->setToolTip( this->absolute_path + "/" + eees.at(i) ); //setting up icons it->setSizeHint( QSize( 100,100 ) ); if ( eees.at(i) == "actorgraphics" ) it->setIcon( QIcon( ":/resources/img/preferences_classes.png" ) ); else if ( eees.at(i) == "animations" ) it->setIcon( QIcon( ":/resources/img/preferences_animations.png" ) ); else if ( eees.at(i) == "autotiles" ) it->setIcon( QIcon( ":/resources/img/preferences_tilesets.png" ) ); else if ( eees.at(i) == "code_snippets" ) it->setIcon( QIcon( ":/resources/img/preferences_system.png" ) ); else if ( eees.at(i) == "faces" ) it->setIcon( QIcon( ":/resources/img/preferences_actors.png" ) ); else if ( eees.at(i) == "music" ) it->setIcon( QIcon( ":/resources/img/preferences_audio.png" ) ); else if ( eees.at(i) == "panoramas" ) it->setIcon( QIcon( ":/resources/img/res_panorama.png" ) ); else if ( eees.at(i) == "pictures" ) it->setIcon( QIcon( ":/resources/img/res_panorama.png" ) ); else if ( eees.at(i) == "soundeffects" ) it->setIcon( QIcon( ":/resources/img/preferences_audio.png" ) ); else if ( eees.at(i) == "sprites" ) it->setIcon( QIcon( ":/resources/img/res_sprites.png" ) ); else if ( eees.at(i) == "tilesets" ) it->setIcon( QIcon( ":/resources/img/preferences_tilesets.png" ) ); else { this->setIconSize( QSize(72,72) ); it->setIcon( QIcon::fromTheme( "folder" ) ); } if ( it->text() != "." ) this->addItem( it ); } //adding files d.cd( this->absolute_path ); eees = d.entryList( QDir::Files, QDir::Name ); for ( int i = 0; i < eees.count(); i++ ) { QListWidgetItem* it = new QListWidgetItem( eees.at(i) ); it->setToolTip( this->absolute_path + "/" + eees.at(i) ); //setting up icons QFileInfo info( it->toolTip() ); const QString ext=info.suffix().toLower(); QIcon icon; if (ext=="ogg" || ext=="wav" || ext=="mp3" ) { icon=QIcon::fromTheme("ausio-x-wav"); } else if (ext=="png" || ext=="jpg" || ext=="gif" || ext=="svg" || ext=="bmp") { // icon=QIcon::fromTheme("image-x-generic"); icon = QIcon( it->toolTip() ); } else { QProxyStyle s; icon=s.standardIcon (QStyle::SP_FileIcon); } it->setSizeHint( QSize( 100,100 ) ); it->setIcon( icon ); if ( it->text() != "." ) this->addItem( it ); } }
QIcon FileChooser::getIcon() { QProxyStyle s; return s.standardIcon(QStyle::SP_FileIcon); }
QIcon Camera::getIcon() { QProxyStyle s; return s.standardIcon(QStyle::SP_FileIcon); }