CColorPopup::CColorPopup (QWidget * parent, const char *name, Qt::WFlags f) :QWidget (parent, name, f) { colorShower = new QLabel (this, "color shower"); colorShower->setFrameStyle (Q3Frame::WinPanel | Q3Frame::Sunken); colorShower->setLineWidth (2); colorShower->setMidLineWidth (1); colorShower->resize (37, 20); colorShower->setPaletteBackgroundColor (QColor (0, 0, 0)); colorShower->move (5, 2); colorName = new Q3TextEdit (this); colorName->resize (55, 20); colorName->move (50, 2); colorName->setHScrollBarMode (Q3ScrollView::AlwaysOff); colorName->setVScrollBarMode (Q3ScrollView::AlwaysOff); QFont f1 ("Times", 8, QFont::Light); colorName->setFont (f1); colorName->clearFocus (); s = new CColorSwatches (this, "", ((CTools *) parent)->dad); s->resize (210, 125); s->move (2, 29); QToolButton * colordialog =new CToolButton (this, tr ("Open color dialog")); colordialog->move (180, 3); colordialog->resize (20, 20); colordialog->setIconSet (QIcon (QPixmap ("colordialogBut.png"))); colordialog->setTextLabel (trUtf8 ("Open Color Dialog")); connect (colordialog, SIGNAL (clicked ()), this,SLOT (slotColordialog ())); //setFocusPolicy (QWidget::StrongFocus); setMouseTracking (true); mcursor = QPixmap ((const char **) eye_dropper_tool_xpm); setCursor (QCursor (mcursor, 1, 15)); }
void NodeTypesDelegate::updateItemWidgets(const QList< QWidget* > widgets, const QStyleOptionViewItem& option, const QPersistentModelIndex& index) const { // widgets: // ColorButton | Title | ID if (!index.isValid()) { return; } Q_ASSERT(widgets.size() == 4); KColorButton *colorButton = qobject_cast<KColorButton*>(widgets.at(0)); QLineEdit *title = qobject_cast<QLineEdit*>(widgets.at(1)); QLabel *id = qobject_cast<QLabel*>(widgets.at(2)); QToolButton *propertiesButton = qobject_cast<QToolButton*>(widgets.at(3)); Q_ASSERT(title); Q_ASSERT(colorButton); Q_ASSERT(id); Q_ASSERT(propertiesButton); colorButton->setColor(index.data(NodeTypeModel::ColorRole).value<QColor>()); title->setText(index.data(NodeTypeModel::TitleRole).toString()); id->setText(index.data(NodeTypeModel::IdRole).toString()); QRect outerRect(0, 0, option.rect.width(), option.rect.height()); QRect contentRect = outerRect.adjusted(m_hPadding, m_vPadding, -m_hPadding, -m_vPadding); int colorButtonLeftMargin = contentRect.left(); int colorButtonTopMargin = (outerRect.height() - colorButton->height()) / 2; colorButton->move(colorButtonLeftMargin, colorButtonTopMargin); int titleLeftMargin = colorButtonLeftMargin + colorButton->width() + 10; int titleTopMargin = (outerRect.height() - title->height()) / 2; title->move(titleLeftMargin, titleTopMargin); // construct remaining from right to left int propertiesLeftMargin = contentRect.right() - propertiesButton->width() - m_hPadding; int propertiesTopMargin = (outerRect.height() - propertiesButton->height()) / 2; propertiesButton->move(propertiesLeftMargin, propertiesTopMargin); int idLeftMargin = propertiesLeftMargin - id->width() - 10; int idTopMargin = (outerRect.height() - id->height()) / 2; id->move(idLeftMargin, idTopMargin); // title gets remaining space title->setFixedWidth(qMax(0, idLeftMargin - titleLeftMargin - 10)); }
void ProgressLineEdit::RepaintButtons () { const int frameWidth = style ()->pixelMetric (QStyle::PM_DefaultFrameWidth); int rightBorder = 0; int realBorder = 0; for (int i = VisibleButtons_.count () - 1; i >= 0; --i) { QToolButton *btn = VisibleButtons_ [i]; const QSize& bmSz = btn->sizeHint (); rightBorder += bmSz.width (); if (i > 0) realBorder += bmSz.width (); btn->move (rect ().right () - frameWidth - rightBorder, (rect ().bottom () + 1 - bmSz.height ()) / 2); } const QMargins& margins = textMargins (); setTextMargins (margins.left (), margins.top (), realBorder + frameWidth, margins.bottom ()); }
void ItemsViewDelegate::updateItemWidgets(const QList<QWidget*> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const { const QSortFilterProxyModel * model = qobject_cast<const QSortFilterProxyModel*>(index.model()); if (model == NULL) { return; } const ItemsModel * realmodel = qobject_cast<const ItemsModel*>(model->sourceModel()); if (realmodel == NULL || !index.isValid()) { return; } // setup the install button int margin = option.fontMetrics.height() / 2; int right = option.rect.width(); //int bottom = option.rect.height(); QSize size(option.fontMetrics.height() * 7, widgets.at(kInstall)->sizeHint().height()); QLabel * infoLabel = qobject_cast<QLabel*>(widgets.at(kLabel)); infoLabel->setWordWrap(true); if (infoLabel != NULL) { if (realmodel->hasPreviewImages()) { // move the text right by kPreviewWidth + margin pixels to fit the preview infoLabel->move(kPreviewWidth + margin * 2, 0); infoLabel->resize(QSize(option.rect.width() - kPreviewWidth - (margin * 6) - size.width(), option.fontMetrics.height() * 7)); } else { infoLabel->move(margin, 0); infoLabel->resize(QSize(option.rect.width() - (margin * 4) - size.width(), option.fontMetrics.height() * 7)); } QString text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">p, li { white-space: pre-wrap; margin:0 0 0 0;}\n" "</style></head><body><p><b>" + index.data(ItemsModel::kNameRole).toString() + "</b></p>\n"; QString summary = "<p>" + option.fontMetrics.elidedText(index.data(ItemsModel::kSummary).toString(), Qt::ElideRight, infoLabel->width() * 3) + "</p>\n"; text += summary; QString authorName = index.data(ItemsModel::kAuthorName).toString(); QString email = index.data(ItemsModel::kAuthorEmail).toString(); if (!authorName.isEmpty()) { if (email.isEmpty()) { text += "<p><i>" + authorName + "</i></p>\n"; } else { text += "<p><i>" + authorName + "</i> <a href=\"mailto:" + email + "\">" + email + "</a></p>\n"; } } unsigned int downloads = index.data(ItemsModel::kDownloads).toUInt(); text += downloads == 0 ? i18n("<p>No Downloads</p>") : i18n("<p>Downloads: %1</p>\n", downloads); text += "</body></html>"; text.replace("[b]", "<b>"); text.replace("[/b]", "</b>"); text.replace("[i]", "<i>"); text.replace("[/i]", "</i>"); text.replace("[u]", "<i>"); text.replace("[/u]", "</i>"); text.remove("[url]"); text.remove("[/url]"); text.replace("\\\'", "\'"); infoLabel->setText(text.simplified()); } QToolButton * button = qobject_cast<QToolButton*>(widgets.at(kInstall)); if (button != NULL) { Entry::Status status = Entry::Status(model->data(index, ItemsModel::kStatus).toUInt()); //if (!button->menu()) { // button->setMenu(InstallMenu(button, status)); // button->setIconSize(QSize(16, 16)); button->resize(size); //} button->move(right - button->width() - margin, option.rect.height() / 2 - button->height()); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); //button->setPopupMode(QToolButton::MenuButtonPopup); // validate our assumptions //Q_ASSERT(button->menu()); //Q_ASSERT(button->menu()->actions().count() == 2); // get the two actions //QAction * action_install = button->menu()->actions()[0]; //QAction * action_uninstall = button->menu()->actions()[1]; switch (status) { case Entry::Installed: button->setText(i18n("Uninstall")); //action_install->setVisible(false); //action_uninstall->setVisible(true); button->setIcon(QIcon(m_statusicons[Entry::Deleted])); break; case Entry::Updateable: button->setText(i18n("Update")); //action_uninstall->setVisible(false); //action_install->setText(i18n("Update")); //action_install->setVisible(true); //action_install->setIcon(QIcon(m_statusicons[Entry::Updateable])); button->setIcon(QIcon(m_statusicons[Entry::Updateable])); break; case Entry::Deleted: /// @todo Set different button text when string freeze is over? "Install again" button->setText(i18n("Install")); //action_uninstall->setVisible(false); //action_install->setText(i18n("Install")); //action_install->setVisible(true); //action_install->setIcon(QIcon(m_statusicons[Entry::Installed])); button->setIcon(QIcon(m_statusicons[Entry::Installed])); break; default: button->setText(i18n("Install")); //action_uninstall->setVisible(false); //action_install->setVisible(true); //action_install->setIcon(QIcon(m_statusicons[Entry::Installed])); button->setIcon(QIcon(m_statusicons[Entry::Installed])); } } QLabel * ratingLabel = qobject_cast<QLabel*>(widgets.at(kRating)); if (ratingLabel != NULL) { ratingLabel->setText(i18n("Rating: %1", model->data(index, ItemsModel::kRating).toString())); // put the rating label below the install button ratingLabel->move(right - button->width() - margin, option.rect.height() / 2 + button->height()/2); ratingLabel->resize(size); } }