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); }
bool ContactListProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); if (!index.isValid()) return false; ContactListItemProxy* itemProxy = static_cast<ContactListItemProxy*>(index.internalPointer()); ContactListItem* item = itemProxy ? itemProxy->item() : 0; if (!item) { Q_ASSERT(false); return false; } if (item->editing()) { return true; } switch (ContactListModel::indexType(index)) { case ContactListModel::ContactType: { PsiContact* psiContact = dynamic_cast<PsiContact*>(item); if (psiContact->isSelf()) { return showSelf(); } else if (psiContact->isAgent()) { return showTransports(); } bool show = true; if (psiContact->isHidden()) { show = showHidden(); } if (!showOffline()) { return show && psiContact->isOnline(); } else { return show; } } case ContactListModel::GroupType: { ContactListGroup::SpecialType specialGroupType = static_cast<ContactListGroup::SpecialType>(index.data(ContactListModel::SpecialGroupTypeRole).toInt()); if (specialGroupType != ContactListGroup::SpecialType_None) { if (specialGroupType == ContactListGroup::SpecialType_Transports) return showTransports(); } bool show = true; if (index.data(Qt::DisplayRole) == PsiContact::hiddenGroupName()) { show = showHidden(); } if (!showOffline()) { ContactListGroup* group = dynamic_cast<ContactListGroup*>(item); return show && group->haveOnlineContacts(); } else { return show; } } case ContactListModel::AccountType: return true; case ContactListModel::InvalidType: return true; default: Q_ASSERT(false); } return true; }