ChooseGeneralDialog::ChooseGeneralDialog(const QStringList &general_names, QWidget *parent) :QDialog(parent), free_chooser(NULL) { setWindowTitle(tr("Choose general")); QString lord_name; QList<const General *> generals; foreach(QString general_name, general_names){ if(general_name.contains("(lord)")) { general_name.chop(6); lord_name = general_name; continue; } const General *general = Sanguosha->getGeneral(general_name); generals << general; } QSignalMapper *mapper = new QSignalMapper(this); QList<OptionButton *> buttons; #ifdef USE_RCC QString category("card2"); #else QString category("card"); #endif QSize icon_size(200*0.8, 290*0.8); if(generals.length() > 10){ category = "big"; icon_size = QSize(94, 96); } foreach(const General *general, generals){ QString icon_path = general->getPixmapPath(category); QString caption = Sanguosha->translate(general->objectName()); OptionButton *button = new OptionButton(icon_path, caption); button->setToolTip(general->getSkillDescription()); button->setIconSize(icon_size); buttons << button; mapper->setMapping(button, general->objectName()); connect(button, SIGNAL(double_clicked()), mapper, SLOT(map())); connect(button, SIGNAL(double_clicked()), this, SLOT(accept())); // special case //if(Self->getRoleEnum() == Player::Lord && general->objectName() == "shencaocao") // button->setEnabled(false); }
void ImageFilesWidget::SetupTable(int sort_column, Qt::SortOrder sort_order) { m_ItemModel->clear(); QStringList header; header.append(tr("Name" )); header.append(tr("File Size (KB)" )); header.append(tr("Times Used" )); header.append(tr("Width" )); header.append(tr("Height" )); header.append(tr("Pixels" )); header.append(tr("Color" )); if (m_ThumbnailSize) { header.append(tr("Image" )); } m_ItemModel->setHorizontalHeaderLabels(header); ui.imageTree->setSelectionBehavior(QAbstractItemView::SelectRows); ui.imageTree->setModel(m_ItemModel); ui.imageTree->header()->setSortIndicatorShown(true); QSize icon_size(m_ThumbnailSize, m_ThumbnailSize); ui.imageTree->setIconSize(icon_size); double total_size = 0; int total_links = 0; QHash<QString, QStringList> image_html_files_hash = m_Book->GetHTMLFilesUsingImages(); foreach (Resource *resource, m_ImageResources) { QString filepath = "../" + resource->GetRelativePathToOEBPS(); QString path = resource->GetFullPath(); QImage image(path); QList<QStandardItem *> rowItems; // Filename QStandardItem *name_item = new QStandardItem(); name_item->setText(resource->Filename()); name_item->setToolTip(filepath); rowItems << name_item; // File Size double ffsize = QFile(path).size() / 1024.0; total_size += ffsize; QString fsize = QLocale().toString(ffsize, 'f', 2); NumericItem *size_item = new NumericItem(); size_item->setText(fsize); rowItems << size_item; // Times Used QStringList image_html_files = image_html_files_hash[filepath]; total_links += image_html_files.count(); NumericItem *link_item = new NumericItem(); link_item->setText(QString::number(image_html_files.count())); if (!image_html_files.isEmpty()) { link_item->setToolTip(image_html_files.join("\n")); } rowItems << link_item; // Width NumericItem *width_item = new NumericItem(); width_item->setText(QString::number(image.width())); rowItems << width_item; // Height NumericItem *height_item = new NumericItem(); height_item->setText(QString::number(image.width())); rowItems << height_item; // Pixels NumericItem *pixel_item = new NumericItem(); pixel_item->setText(QString::number(image.width() * image.height())); rowItems << pixel_item; // Color QStandardItem *color_item = new QStandardItem(); color_item->setText(image.allGray() ? "Grayscale" : "Color"); rowItems << color_item; // Thumbnail if (m_ThumbnailSize) { QPixmap pixmap(resource->GetFullPath()); if (pixmap.height() > m_ThumbnailSize || pixmap.width() > m_ThumbnailSize) { pixmap = pixmap.scaled(QSize(m_ThumbnailSize, m_ThumbnailSize), Qt::KeepAspectRatio); } QStandardItem *icon_item = new QStandardItem(); icon_item->setIcon(QIcon(pixmap)); rowItems << icon_item; } for (int i = 0; i < rowItems.count(); i++) { rowItems[i]->setEditable(false); } m_ItemModel->appendRow(rowItems); }