void SearchResultListView::updateActions() { QModelIndexList indexes = selectionModel()->selection().indexes(); if (indexes.size() != 0) { FileSearchResult file = getSearchResult(indexes.at(0)); open_parent_dir_action_->setData(QVariant::fromValue(file)); open_parent_dir_action_->setEnabled(true); } else { open_parent_dir_action_->setEnabled(false); } }
void SearchResultItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { const SearchResultListModel *model = static_cast<const SearchResultListModel*>(index.model()); QBrush backBrush; bool selected = false; FileSearchResult file = getSearchResult(index); if (option.state & (QStyle::State_HasFocus | QStyle::State_Selected)) { backBrush = QColor(kFileItemBackgroundColorHighlighted); selected = true; } else { backBrush = QColor(kFileItemBackgroundColor); } // // draw item's background // painter->save(); painter->fillRect(option.rect, backBrush); painter->restore(); QIcon icon = model->data(index, Qt::DecorationRole).value<QIcon>(); // get the device pixel radio from current painter device int scale_factor = 1; #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) scale_factor = painter->device()->devicePixelRatio(); #endif // QT5 QPixmap pixmap(icon.pixmap(QSize(kFileIconWidth, kFileIconHeight) * scale_factor)); #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) if (pixmap.size() != QSize(kFileIconWidth, kFileIconHeight)) pixmap.setDevicePixelRatio(scale_factor); #endif // QT5 // // paint file icon // QPoint file_icon_pos(kMarginLeft + kPadding, kMarginTop + kPadding); file_icon_pos += option.rect.topLeft(); painter->save(); painter->drawPixmap(file_icon_pos, pixmap); painter->restore(); // Calculate the file column by the delta of mainwindow's width QString title = file.name; const int file_name_width = kFileNameWidth + seafApplet->mainWindow()->width() - seafApplet->mainWindow()->minimumWidth(); painter->save(); QPoint file_name_pos = file_icon_pos + QPoint(kFileIconWidth + kMarginBetweenFileIconAndName, -kPadding); QRect file_name_rect(file_name_pos, QSize(file_name_width, kFileNameHeight)); painter->setPen(QColor(selected ? kFileNameColorHighlighted : kFileNameColor)); painter->setFont(changeFontSize(painter->font(), kFileNameFontSize)); painter->drawText(file_name_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(title, option.font, file_name_width), &file_name_rect); painter->restore(); // // Paint repo_name // int count_of_splash = file.fullpath.endsWith("/") ? 2 : 1; QString subtitle = file.fullpath.mid(1, file.fullpath.size() - count_of_splash - file.name.size()); if (!subtitle.isEmpty()) subtitle = file.repo_name + "/" + subtitle.left(subtitle.size() - 1); else subtitle = file.repo_name; painter->save(); QPoint file_desc_pos = file_name_rect.bottomLeft() + QPoint(0, kPadding / 2); QRect file_desc_rect(file_desc_pos, QSize(file_name_width, kSubtitleHeight)); painter->setFont(changeFontSize(painter->font(), kSubtitleFontSize)); painter->setPen(QColor(selected ? kSubtitleColorHighlighted : kSubtitleColor)); painter->drawText(file_desc_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(subtitle, option.font, file_name_width), &file_desc_rect); painter->restore(); // // Paint file description // QString size, mtime; size = readableFileSize(file.size); mtime = translateCommitTime(file.last_modified); QString extra_title = size + " " + mtime; painter->save(); QPoint file_extra_pos = file_desc_rect.bottomLeft() + QPoint(0, kPadding / 2 + 2); QRect file_extra_rect(file_extra_pos, QSize(file_name_width, kSubtitleHeight)); painter->setFont(changeFontSize(painter->font(), kSubtitleFontSize)); painter->setPen(QColor(selected ? kSubtitleColorHighlighted : kSubtitleColor)); painter->drawText(file_extra_rect, Qt::AlignLeft | Qt::AlignTop, fitTextToWidth(extra_title, option.font, file_name_width), &file_extra_rect); painter->restore(); // // Draw the bottom border lines // painter->save(); painter->setPen(QPen(QColor(kItemBottomBorderColor), 1, Qt::SolidLine)); painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); painter->restore(); }
void GUI::EverywhereWindow::createMenu() { AWidget *widget = new GUI::Library(this); _menuWidgets["libraryButton"] = std::make_pair("library", widget); connect(ui->libraryButton, SIGNAL(clicked()), this, SLOT(switchView())); widget->hide(); ui->gridLayout->addWidget(widget, 3, 0, 1, 2); AWidget *widget2 = new GUI::News(this); _menuWidgets["newButton"] = std::make_pair("new", widget2); connect(ui->newButton, SIGNAL(clicked()), this, SLOT(switchView())); widget2->hide(); ui->gridLayout->addWidget(widget2, 4, 0, 1, 2); AWidget *widget3 = new GUI::Radio(this); _menuWidgets["radioButton"] = std::make_pair("radio", widget3); connect(ui->radioButton, SIGNAL(clicked()), this, SLOT(switchView())); widget3->hide(); ui->gridLayout->addWidget(widget3, 5, 0, 1, 2); AWidget *widget4 = new GUI::Download(this); _menuWidgets["downloadButton"] = std::make_pair("download", widget4); connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(switchView())); widget4->hide(); ui->gridLayout->addWidget(widget4, 6, 0, 1, 2); AWidget *widget5 = new GUI::Research(this); _menuWidgets["researchButton"] = std::make_pair("research", widget5); connect(ui->researchButton, SIGNAL(clicked()), this, SLOT(switchView())); widget5->hide(); ui->gridLayout->addWidget(widget5, 6, 0, 1, 2); AWidget *widget6 = new GUI::Stream(this); _menuWidgets["streamButton"] = std::make_pair("stream", widget6); connect(ui->streamButton, SIGNAL(clicked()), this, SLOT(switchView())); widget6->hide(); ui->gridLayout->addWidget(widget6, 7, 0, 1, 2); AWidget *widget7 = new GUI::Synchronization(this); _menuWidgets["synchronizationButton"] = std::make_pair("synchronization", widget7); connect(ui->synchronizationButton, SIGNAL(clicked()), this, SLOT(switchView())); widget7->hide(); ui->gridLayout->addWidget(widget7, 8, 0, 1, 2); AWidget *widget8 = new GUI::Profil(this); _menuWidgets["profilButton"] = std::make_pair("profil", widget8); connect(dynamic_cast<GUI::Profil *>(widget8), SIGNAL(deleted()), _parent, SLOT(showConnection())); connect(ui->profilButton, SIGNAL(clicked()), this, SLOT(switchView())); widget8->hide(); ui->gridLayout->addWidget(widget8, 9, 0, 1, 2); AWidget *widget9 = new GUI::Disconnect(this); _menuWidgets["disconnectButton"] = std::make_pair("disconnect", widget9); connect(ui->disconnectButton, SIGNAL(clicked()), this, SLOT(switchView())); widget9->hide(); ui->gridLayout->addWidget(widget9, 10, 0, 1, 2); AWidget *widget10 = new GUI::ResultSearch(this); _menuWidgets["searchButton"] = std::make_pair("resultSearch", widget10); connect(ui->searchButton, SIGNAL(clicked()), this, SLOT(getSearchResult())); connect(dynamic_cast<GUI::ResultSearch *>(widget10), SIGNAL(goToResult()), this, SLOT(showResult())); widget10->hide(); ui->gridLayout->addWidget(widget10, 11, 0, 1, 2); AWidget *widget11 = new GUI::Result(this); _menuWidgets["ResultView"] = std::make_pair("Result", widget11); widget11->hide(); ui->gridLayout->addWidget(widget11, 12, 0, 1, 2); }