Esempio n. 1
0
void tst_QStandardItem::clone()
{
    QStandardItem item;
    item.setText(QLatin1String("text"));
    item.setToolTip(QLatin1String("toolTip"));
    item.setStatusTip(QLatin1String("statusTip"));
    item.setWhatsThis(QLatin1String("whatsThis"));
    item.setSizeHint(QSize(64, 48));
    item.setFont(QFont());
    item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
    item.setBackground(QColor(Qt::blue));
    item.setForeground(QColor(Qt::green));
    item.setCheckState(Qt::PartiallyChecked);
    item.setAccessibleText(QLatin1String("accessibleText"));
    item.setAccessibleDescription(QLatin1String("accessibleDescription"));
    item.setFlags(Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);

    QStandardItem *clone = item.clone();
    QCOMPARE(clone->text(), item.text());
    QCOMPARE(clone->toolTip(), item.toolTip());
    QCOMPARE(clone->statusTip(), item.statusTip());
    QCOMPARE(clone->whatsThis(), item.whatsThis());
    QCOMPARE(clone->sizeHint(), item.sizeHint());
    QCOMPARE(clone->font(), item.font());
    QCOMPARE(clone->textAlignment(), item.textAlignment());
    QCOMPARE(clone->background(), item.background());
    QCOMPARE(clone->foreground(), item.foreground());
    QCOMPARE(clone->checkState(), item.checkState());
    QCOMPARE(clone->accessibleText(), item.accessibleText());
    QCOMPARE(clone->accessibleDescription(), item.accessibleDescription());
    QCOMPARE(clone->flags(), item.flags());
    QVERIFY(!(*clone < item));
    delete clone;
}
Esempio n. 2
0
/* 
  Update the contents for the message pointed to by 'msg', if it's in the
  model, otherwise ignore the request.  Currently the contents are the
  status (icon) and the priority. Other changes such as in the subject
  or the date could be visually reflected by this function if the UI
  permitted those changes.
*/
void
mail_item_model::update_msg(const mail_msg* msg)
{
  DBG_PRINTF(4, "update_msg of " MAIL_ID_FMT_STRING, msg->get_id());
  QStandardItem* item=item_from_id(msg->get_id());
  if (!item)
    return;
  QModelIndex index=item->index();
  QStandardItem* isubject = itemFromIndex(index);
  bool bold=isubject->font().bold();
  DBG_PRINTF(5, "mail_id=" MAIL_ID_FMT_STRING ", status=%d, bold=%d",
	     msg->get_id(), msg->status(), bold);
  if ((msg->status()!=0 && bold) || (msg->status()==0 && !bold)) {
    // reverse bold attribute
    QFont f=isubject->font();
    f.setBold(!bold);
    isubject->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_sender))->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_date))->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_pri))->setFont(f);
    itemFromIndex(index.sibling(index.row(), column_recipient))->setFont(f);
  }

  // status icon
  QIcon* icon = icon_status(msg->status());
  QStandardItem* istatus = itemFromIndex(index.sibling(index.row(), column_status));
  if (istatus) {
    if (icon)
      istatus->setIcon(*icon);
    else
      istatus->setIcon(QIcon());
  }

  // priority
  QStandardItem* ipri = itemFromIndex(index.sibling(index.row(), column_pri));
  if (ipri) {
    if (msg->priority()!=0)
      ipri->setText(QString("%1").arg(msg->priority()));
    else
      ipri->setText("");
  }

  // note
  QStandardItem* inote = itemFromIndex(index.sibling(index.row(), column_note));
  if (inote) {
    inote->setData(msg->has_note());
    if (msg->has_note())
      inote->setIcon(STATUS_ICON(FT_ICON16_EDIT_NOTE));
    else
      inote->setIcon(QIcon());
  }

}
void ConfigurationContentsWidget::optionChanged(const QString &option, const QVariant &value)
{
	for (int i = 0; i < m_model->rowCount(); ++i)
	{
		QStandardItem *groupItem = m_model->item(i, 0);

		if (!groupItem || !QString(option).startsWith(groupItem->text()))
		{
			continue;
		}

		for (int j = 0; j < groupItem->rowCount(); ++j)
		{
			QStandardItem *optionItem = groupItem->child(j, 0);

			if (optionItem && option == QStringLiteral("%1/%2").arg(groupItem->text()).arg(optionItem->text()))
			{
				QFont font = optionItem->font();
				font.setBold(value != SettingsManager::getDefaultValue(option));

				optionItem->setFont(font);

				groupItem->child(j, 2)->setText(value.toString());

				break;
			}
		}
	}
}
QList<QStandardItem*> QDatabaseTableViewController::makeStandardItemListFromStringList(const QList<QString>& szStringList)
{
	QList<QStandardItem*> listStandardItemList;
	QStandardItem* pStandardItem;
	QFont font;

	QPalette palette = QApplication::palette(m_pDatabaseTableView);
	QBrush nullbrush = palette.brush(QPalette::Disabled, QPalette::Text);

	QList<QString>::const_iterator iter = szStringList.begin();
	while(iter != szStringList.end())
	{
		//Getting an item from QList<QString> to add it to a QList<QStandardItem>
		if((*iter).isNull()){
			pStandardItem = new QStandardItem(QString("NULL"));
			font = pStandardItem->font();
			font.setItalic(true);
			pStandardItem->setFont(font);
			pStandardItem->setForeground(nullbrush);
		} else {
			pStandardItem = new QStandardItem(*iter);
		}
		pStandardItem->setEditable(true);
		listStandardItemList.append(pStandardItem);
		iter++;
	}
	return listStandardItemList;
}
    foreach (QComboBox *comboBox, comboBoxes) {
      // insert title
      int titleIndex = comboBox->count();
      if (dimensionality != std::numeric_limits<int>::max())
        comboBox->addItem(tr("%1D Descriptors").arg(dimensionality));
      else
        comboBox->addItem(tr("Other Descriptors"));

      // set bold font for title and make it non-selectable
      QStandardItem *item =
        qobject_cast<QStandardItemModel *>(comboBox->model())->item(titleIndex);

      if (item) {
        QFont font_ = item->font();
        font_.setBold(true);
        item->setFont(font_);
        item->setFlags(Qt::ItemIsEnabled);
      }

      // add a separator
      comboBox->insertSeparator(comboBox->count());

      // insert name of each descriptor
      foreach (const QString &name, names)
        comboBox->addItem(name);
    }
Esempio n. 6
0
void MessagesModel::addMessage(const QString &id, const QString &parentId, const QString &subject, const QString &from, const QDateTime &received, bool read)
{
    QStandardItem *stdItem = findItem(id);
    if (stdItem) {
        return;
    }

    QList<QStandardItem*> items;
    stdItem = new QStandardItem;
    QFont font = stdItem->font();
    font.setBold(true);
    if (!read) {
        stdItem->setFont(font);
    }
    stdItem->setText(from);
    stdItem->setData(id, RoleMessageId);
    stdItem->setData(parentId, RoleParentFolderId);
    items << stdItem;

    stdItem = new QStandardItem(subject);
    if (!read) {
        stdItem->setFont(font);
    }
    items << stdItem;

    stdItem = new QStandardItem;
    if (!read) {
        stdItem->setFont(font);
    }
    stdItem->setData(received, Qt::DisplayRole);
    items << stdItem;

    appendRow(items);
}
QStandardItem* FontManagerDialog::CreateFontItem(QString itemText, QString fontName, QString defaultFontName)
{
	QStandardItem *item = new QStandardItem(itemText);
	if (!defaultFontName.isNull() && !defaultFontName.isEmpty() && defaultFontName.contains(fontName))
	{
		QFont itemFont = item->font();
		itemFont.setBold(true);
	    item->setFont(itemFont);
	}
	return item;
}
Esempio n. 8
0
void tst_QStandardItem::streamItem()
{
    QStandardItem item;
    
    item.setText(QLatin1String("text"));
    item.setToolTip(QLatin1String("toolTip"));
    item.setStatusTip(QLatin1String("statusTip"));
    item.setWhatsThis(QLatin1String("whatsThis"));
    item.setSizeHint(QSize(64, 48));
    item.setFont(QFont());
    item.setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
    item.setBackground(QColor(Qt::blue));
    item.setForeground(QColor(Qt::green));
    item.setCheckState(Qt::PartiallyChecked);
    item.setAccessibleText(QLatin1String("accessibleText"));
    item.setAccessibleDescription(QLatin1String("accessibleDescription"));

    QByteArray ba;
    {
        QDataStream ds(&ba, QIODevice::WriteOnly);
        ds << item;
    }
    {
        QStandardItem streamedItem;
        QDataStream ds(&ba, QIODevice::ReadOnly);
        ds >> streamedItem;
        QCOMPARE(streamedItem.text(), item.text());
        QCOMPARE(streamedItem.toolTip(), item.toolTip());
        QCOMPARE(streamedItem.statusTip(), item.statusTip());
        QCOMPARE(streamedItem.whatsThis(), item.whatsThis());
        QCOMPARE(streamedItem.sizeHint(), item.sizeHint());
        QCOMPARE(streamedItem.font(), item.font());
        QCOMPARE(streamedItem.textAlignment(), item.textAlignment());
        QCOMPARE(streamedItem.background(), item.background());
        QCOMPARE(streamedItem.foreground(), item.foreground());
        QCOMPARE(streamedItem.checkState(), item.checkState());
        QCOMPARE(streamedItem.accessibleText(), item.accessibleText());
        QCOMPARE(streamedItem.accessibleDescription(), item.accessibleDescription());
        QCOMPARE(streamedItem.flags(), item.flags());
    }
}
bool QgsStyleExportImportDialog::populateStyles( QgsStyle *style )
{
  // load symbols and color ramps from file
  if ( mDialogMode == Import )
  {
    // NOTE mTempStyle is style here
    if ( !style->importXml( mFileName ) )
    {
      QMessageBox::warning( this, tr( "Import error" ),
                            tr( "An error occurred during import:\n%1" ).arg( style->errorString() ) );
      return false;
    }
  }

  QStandardItemModel *model = qobject_cast<QStandardItemModel *>( listItems->model() );
  model->clear();

  // populate symbols
  QStringList styleNames = style->symbolNames();
  QString name;

  for ( int i = 0; i < styleNames.count(); ++i )
  {
    name = styleNames[i];
    QStringList tags = style->tagsOfSymbol( QgsStyle::SymbolEntity, name );
    QgsSymbol *symbol = style->symbol( name );
    QStandardItem *item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize(), 15 );
    item->setIcon( icon );
    item->setToolTip( QString( "<b>%1</b><br><i>%2</i>" ).arg( name, tags.count() > 0 ? tags.join( ", " ) : tr( "Not tagged" ) ) );
    // Set font to 10points to show reasonable text
    QFont itemFont = item->font();
    itemFont.setPointSize( 10 );
    item->setFont( itemFont );
    model->appendRow( item );
    delete symbol;
  }

  // and color ramps
  styleNames = style->colorRampNames();

  for ( int i = 0; i < styleNames.count(); ++i )
  {
    name = styleNames[i];
    std::unique_ptr< QgsColorRamp > ramp( style->colorRamp( name ) );

    QStandardItem *item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), listItems->iconSize(), 15 );
    item->setIcon( icon );
    model->appendRow( item );
  }
  return true;
}
Esempio n. 10
0
// ------------------------------------------------------------------
void
JcnModel::markEntry(int r, int markCol)
{
	if (jcndbg)
		std::cout << "JcnModel::markEntry r c" << std::endl;

	QStandardItem * itm = item(r,markCol);
	QFont f = itm->font();
	f.setBold(true);
	f.setUnderline(true);
	f.setPixelSize(13);
	itm->setFont(f);
}
Esempio n. 11
0
void ObxTreeViewItem::paintEvent(QPaintEvent *)
{
    if (view_.header().model() == 0 || data() == 0)
    {
        return;
    }

    QPainter p(this);
    for(int i = 0; i < view_.header().model()->columnCount(); ++i)
    {
        QRect rc(view_.header().columnRect(i));
        rc.setTop(MARGIN);
        rc.setHeight(height() - 2 * MARGIN);
        QStandardItem * item = view_.item(data(), i);
        if (item != 0)
        {
            rc.adjust(ITEM_HEIGHT + MARGIN, MARGIN, -MARGIN * 4, -MARGIN);

            if (i == 0)
            {
                rc.setLeft(rc.left() + obx::indent(item));
            }

            p.setOpacity(item->isSelectable() ? 1.0 : 0.5);

            QIcon icon = item->icon();
            p.drawPixmap(8, 8, icon.pixmap(84, 84));

            QString title = item->text();
            p.setFont(item->font());
            chopStringByRect(p, rc, item->textAlignment()|Qt::AlignTop, title);
            p.drawText(rc, item->textAlignment()|Qt::AlignTop, title);

            QFont smallFont;
            smallFont.setPointSize(16);
            title = item->toolTip();
            p.setFont(smallFont);
            chopStringByRect(p, rc, Qt::AlignRight|Qt::AlignBottom, title);
            p.drawText(rc, Qt::AlignRight|Qt::AlignBottom, title);
        }
    }

    if (isSelected())
    {
        p.setOpacity(1);
        QPen pen(Qt::SolidLine);
        pen.setColor(Qt::black);
        p.setPen(pen);
        p.drawRoundedRect(rect().adjusted(0, 0, -1, -1), 8, 8);
    }
}
void Ui_pluginManagerWindow::clearDefaultRow(int defaultRow)
{
	QStandardItemModel *model = (QStandardItemModel*)ui.pluginTableView->model();
	QStandardItem *item = model->item(defaultRow, 0);

	item->setData(false, PLUGIN_IS_DEFAULT);

	for (int column = 0; column < model->columnCount(); column++)
	{
		QStandardItem *item = model->item(defaultRow, column);
		QFont font = item->font();

		font.setBold(false);
		item->setFont(font);
	}
}
Esempio n. 13
0
bool DebuggerItemModel::updateDebuggerStandardItem(const DebuggerItem &item, bool changed)
{
    QStandardItem *sitem = findStandardItemById(item.id());
    QTC_ASSERT(sitem, return false);
    QStandardItem *parent = sitem->parent();
    QTC_ASSERT(parent, return false);
    int row = sitem->row();
    QFont font = sitem->font();
    font.setBold(changed);
    parent->child(row, 0)->setData(item.displayName(), Qt::DisplayRole);
    parent->child(row, 0)->setData(item.abiNames(), Qt::UserRole + 2);
    parent->child(row, 0)->setFont(font);
    parent->child(row, 1)->setData(item.command().toUserOutput(), Qt::DisplayRole);
    parent->child(row, 1)->setFont(font);
    parent->child(row, 2)->setData(item.engineTypeName(), Qt::DisplayRole);
    parent->child(row, 2)->setData(static_cast<int>(item.engineType()));
    parent->child(row, 2)->setFont(font);
    return true;
}
bool LogChangeWidget::populateLog(const QString &repository, const QString &commit, LogFlags flags)
{
    const QString currentCommit = this->commit();
    int selected = currentCommit.isEmpty() ? 0 : -1;
    if (const int rowCount = m_model->rowCount())
        m_model->removeRows(0, rowCount);

    // Retrieve log using a custom format "Sha1:Subject [(refs)]"
    GitClient *client = GitPlugin::instance()->gitClient();
    QStringList arguments;
    arguments << QLatin1String("--max-count=1000") << QLatin1String("--format=%h:%s %d");
    arguments << (commit.isEmpty() ? QLatin1String("HEAD") : commit);
    if (!(flags & IncludeRemotes))
        arguments << QLatin1String("--not") << QLatin1String("--remotes");
    QString output;
    if (!client->synchronousLog(repository, arguments, &output, 0, VcsBasePlugin::NoOutput))
        return false;
    foreach (const QString &line, output.split(QLatin1Char('\n'))) {
        const int colonPos = line.indexOf(QLatin1Char(':'));
        if (colonPos != -1) {
            QList<QStandardItem *> row;
            for (int c = 0; c < ColumnCount; ++c) {
                QStandardItem *item = new QStandardItem;
                item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
                if (line.endsWith(QLatin1Char(')'))) {
                    QFont font = item->font();
                    font.setBold(true);
                    item->setFont(font);
                }
                row.push_back(item);
            }
            const QString sha1 = line.left(colonPos);
            row[Sha1Column]->setText(sha1);
            row[SubjectColumn]->setText(line.right(line.size() - colonPos - 1));
            m_model->appendRow(row);
            if (selected == -1 && currentCommit == sha1)
                selected = m_model->rowCount() - 1;
        }
    }
    setCurrentIndex(m_model->index(selected, 0));
    return true;
}
void MpcImportWindow::populateCandidateObjects(QList<SsoElements> objects)
{
	candidatesForAddition.clear();

	//Get a list of the current objects
	QHash<QString,QString> defaultSsoIdentifiers = ssoManager->getDefaultSsoIdentifiers();
	QHash<QString,QString> loadedSsoIdentifiers = ssoManager->listAllLoadedSsoIdentifiers();

	//Separating the objects into visual groups in the list
	int newDefaultSsoIndex = 0;
	int newLoadedSsoIndex = 0;
	int newNovelSsoIndex = 0;
	int insertionIndex = 0;

	QStandardItemModel * model = candidateObjectsModel;
	model->clear();
	model->setColumnCount(1);

	foreach (SsoElements object, objects)
	{
		QString name = object.value("name").toString();
		if (name.isEmpty())
			continue;

		QString group = object.value("section_name").toString();
		if (group.isEmpty())
			continue;

		//Prevent name conflicts between asteroids and moons
		if (loadedSsoIdentifiers.contains(name))
		{
			if (loadedSsoIdentifiers.value(name) != group)
			{
				name.append('*');
				object.insert("name", name);
			}
		}

		QStandardItem * item = new QStandardItem();
		item->setText(name);
		item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
		item->setCheckState(Qt::Unchecked);

		if (defaultSsoIdentifiers.contains(name))
		{
			//Duplicate of a default solar system object
			QFont itemFont(item->font());
			itemFont.setBold(true);
			item->setFont(itemFont);

			candidatesForUpdate.append(object);

			insertionIndex = newDefaultSsoIndex;
			newDefaultSsoIndex++;
			newLoadedSsoIndex++;
			newNovelSsoIndex++;
		}
		else if (loadedSsoIdentifiers.contains(name))
		{
			//Duplicate of another existing object
			QFont itemFont(item->font());
			itemFont.setItalic(true);
			item->setFont(itemFont);

			candidatesForUpdate.append(object);

			insertionIndex = newLoadedSsoIndex;
			newLoadedSsoIndex++;
			newNovelSsoIndex++;
		}
		else
		{
			candidatesForAddition.append(object);

			insertionIndex = newNovelSsoIndex;
			newNovelSsoIndex++;
		}

		model->insertRow(insertionIndex, item);
	}
Esempio n. 16
0
void CLvQInfo::fillInfo(ofiItem_t *data, bool update)
/////////////////////////////////////////////////////
{
  m_bFilled = true;

  m_info = *data;
  m_parent->setItemText(0, tr("Quick information : ") + data->title);

  QStandardItemModel *m = (QStandardItemModel *)model();

  if (!update)
  {
    m->removeRows(0, m->rowCount());
  }

  for (int i = 0; i < data->tTextItem.count(); i++)
  {
    ofiTextItem_t *item = &data->tTextItem[i];

    if (update)
    {
      m->item(i, 1)->setText(item->value);
    }
    else
    {
      QList <QStandardItem *> tRow;
      QStandardItem *label = new QStandardItem;
      QStandardItem *value = new QStandardItem;

      QFont f = label->font();
      f.setPointSizeF(f.pointSizeF() - 0.25);
      label->setFont(f);
      value->setFont(f);

      label->setText(item->label);
      label->setToolTip(item->label);

      if (item->bBold)
      {
        QFont f = label->font();
        f.setBold(true);
        label->setFont(f);
      }

      if (!item->bIsTitle)
      {
        value->setText(item->value);
        value->setToolTip(item->value);
      }

      tRow.append(label);
      tRow.append(value);

      m->appendRow(tRow);

      if (item->bIsTitle)
      {
        setFirstColumnSpanned(i, QModelIndex(), true);
      }
    }
  }
}
Esempio n. 17
0
void MidiInstrument::populatePatchModel(QStandardItemModel* model, int chan, MidiType songType)
{
    model->clear();
    int mask = 0;
    bool drumchan = chan == 9;
    switch (songType)
    {
        case MIDI_TYPE_XG:
            mask = 4;
            break;
        case MIDI_TYPE_GS:
            mask = 2;
            break;
        case MIDI_TYPE_GM:
            if (drumchan)
                return;
            mask = 1;
            break;
        case MIDI_TYPE_NULL:
            mask = 7;
            break;
    }
    if (pg.size() > 1)
    {
        for (ciPatchGroup i = pg.begin(); i != pg.end(); ++i)
        {
            PatchGroup* pgp = *i;
            QList<QStandardItem*> folder;
            QStandardItem* noop = new QStandardItem("");
            QStandardItem *dir = new QStandardItem(pgp->name);
            QFont f = dir->font();
            f.setBold(true);
            dir->setFont(f);
            const PatchList& pl = pgp->patches;
            for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl)
            {
                const Patch* mp = *ipl;
                if (mp->typ & mask)
                {
                    int id = ((mp->hbank & 0xff) << 16) + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
                    QList<QStandardItem*> row;
                    QString strId = QString::number(id);
                    QStandardItem* idItem = new QStandardItem(strId);
                    QStandardItem* nItem = new QStandardItem(mp->name);
                    nItem->setToolTip(QString(pgp->name+":\n    "+mp->name));
                    row.append(nItem);
                    row.append(idItem);
                    dir->appendRow(row);
                }

            }
            folder.append(dir);
            folder.append(noop);
            model->appendRow(folder);
        }
    }
    else if (pg.size() == 1)
    {
        // no groups
        const PatchList& pl = pg.front()->patches;
        QStandardItem* root = model->invisibleRootItem();
        for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl)
        {
            const Patch* mp = *ipl;
            if (mp->typ & mask)
            {
                int id = ((mp->hbank & 0xff) << 16) + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
                QList<QStandardItem*> row;
                QString strId = QString::number(id);
                QStandardItem* idItem = new QStandardItem(strId);
                QStandardItem* nItem = new QStandardItem(mp->name);
                nItem->setToolTip(QString(mp->name));
                row.append(nItem);
                row.append(idItem);
                root->appendRow(row);
            }
        }
    }
}
Esempio n. 18
0
void tst_QStandardItem::getSetData()
{
    QStandardItem item;
    for (int x = 0; x < 2; ++x) {
        for (int i = 1; i <= 2; ++i) {
            QString text = QString("text %0").arg(i);
            item.setText(text);
            QCOMPARE(item.text(), text);
            
            QPixmap pixmap(32, 32);
            pixmap.fill((i == 1) ? Qt::red : Qt::green);
            QIcon icon(pixmap);
            item.setIcon(icon);
            QCOMPARE(item.icon(), icon);
            
            QString toolTip = QString("toolTip %0").arg(i);
            item.setToolTip(toolTip);
            QCOMPARE(item.toolTip(), toolTip);
            
            QString statusTip = QString("statusTip %0").arg(i);
            item.setStatusTip(statusTip);
            QCOMPARE(item.statusTip(), statusTip);
        
            QString whatsThis = QString("whatsThis %0").arg(i);
            item.setWhatsThis(whatsThis);
            QCOMPARE(item.whatsThis(), whatsThis);
            
            QSize sizeHint(64*i, 48*i);
            item.setSizeHint(sizeHint);
            QCOMPARE(item.sizeHint(), sizeHint);
            
            QFont font;
            item.setFont(font);
            QCOMPARE(item.font(), font);
        
            Qt::Alignment textAlignment((i == 1)
                                        ? Qt::AlignLeft|Qt::AlignVCenter
                                        : Qt::AlignRight);
            item.setTextAlignment(textAlignment);
            QCOMPARE(item.textAlignment(), textAlignment);
            
            QColor backgroundColor((i == 1) ? Qt::blue : Qt::yellow);
            item.setBackground(backgroundColor);
            QCOMPARE(item.background().color(), backgroundColor);
            
            QColor textColor((i == i) ? Qt::green : Qt::cyan);
            item.setForeground(textColor);
            QCOMPARE(item.foreground().color(), textColor);
            
            Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked);
            item.setCheckState(checkState);
            QCOMPARE(item.checkState(), checkState);
            
            QString accessibleText = QString("accessibleText %0").arg(i);
            item.setAccessibleText(accessibleText);
            QCOMPARE(item.accessibleText(), accessibleText);
            
            QString accessibleDescription = QString("accessibleDescription %0").arg(i);
            item.setAccessibleDescription(accessibleDescription);
            QCOMPARE(item.accessibleDescription(), accessibleDescription);
            
            QCOMPARE(item.text(), text);
            QCOMPARE(item.icon(), icon);
            QCOMPARE(item.toolTip(), toolTip);
            QCOMPARE(item.statusTip(), statusTip);
            QCOMPARE(item.whatsThis(), whatsThis);
            QCOMPARE(item.sizeHint(), sizeHint);
            QCOMPARE(item.font(), font);
            QCOMPARE(item.textAlignment(), textAlignment);
            QCOMPARE(item.background().color(), backgroundColor);
            QCOMPARE(item.foreground().color(), textColor);
            QCOMPARE(item.checkState(), checkState);
            QCOMPARE(item.accessibleText(), accessibleText);
            QCOMPARE(item.accessibleDescription(), accessibleDescription);
            
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::DisplayRole)), text);
            QCOMPARE(qvariant_cast<QIcon>(item.data(Qt::DecorationRole)), icon);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::ToolTipRole)), toolTip);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::StatusTipRole)), statusTip);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::WhatsThisRole)), whatsThis);
            QCOMPARE(qvariant_cast<QSize>(item.data(Qt::SizeHintRole)), sizeHint);
            QCOMPARE(qvariant_cast<QFont>(item.data(Qt::FontRole)), font);
            QCOMPARE(qvariant_cast<int>(item.data(Qt::TextAlignmentRole)), int(textAlignment));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundColorRole)), QBrush(backgroundColor));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)), QBrush(backgroundColor));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::TextColorRole)), QBrush(textColor));
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::ForegroundRole)), QBrush(textColor));
            QCOMPARE(qvariant_cast<int>(item.data(Qt::CheckStateRole)), int(checkState));
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleTextRole)), accessibleText);
            QCOMPARE(qvariant_cast<QString>(item.data(Qt::AccessibleDescriptionRole)), accessibleDescription);

            item.setBackground(pixmap);
            QCOMPARE(item.background().texture(), pixmap);
            QCOMPARE(qvariant_cast<QBrush>(item.data(Qt::BackgroundRole)).texture(), pixmap);
        }
        item.setData(QVariant(), Qt::DisplayRole);
        item.setData(QVariant(), Qt::DecorationRole);
        item.setData(QVariant(), Qt::ToolTipRole);
        item.setData(QVariant(), Qt::StatusTipRole);
        item.setData(QVariant(), Qt::WhatsThisRole);
        item.setData(QVariant(), Qt::SizeHintRole);
        item.setData(QVariant(), Qt::FontRole);
        item.setData(QVariant(), Qt::TextAlignmentRole);
        item.setData(QVariant(), Qt::BackgroundRole);
        item.setData(QVariant(), Qt::ForegroundRole);
        item.setData(QVariant(), Qt::CheckStateRole);
        item.setData(QVariant(), Qt::AccessibleTextRole);
        item.setData(QVariant(), Qt::AccessibleDescriptionRole);
        
        QCOMPARE(item.data(Qt::DisplayRole), QVariant());
        QCOMPARE(item.data(Qt::DecorationRole), QVariant());
        QCOMPARE(item.data(Qt::ToolTipRole), QVariant());
        QCOMPARE(item.data(Qt::StatusTipRole), QVariant());
        QCOMPARE(item.data(Qt::WhatsThisRole), QVariant());
        QCOMPARE(item.data(Qt::SizeHintRole), QVariant());
        QCOMPARE(item.data(Qt::FontRole), QVariant());
        QCOMPARE(item.data(Qt::TextAlignmentRole), QVariant());
        QCOMPARE(item.data(Qt::BackgroundColorRole), QVariant());
        QCOMPARE(item.data(Qt::BackgroundRole), QVariant());
        QCOMPARE(item.data(Qt::TextColorRole), QVariant());
        QCOMPARE(item.data(Qt::ForegroundRole), QVariant());
        QCOMPARE(item.data(Qt::CheckStateRole), QVariant());
        QCOMPARE(item.data(Qt::AccessibleTextRole), QVariant());
        QCOMPARE(item.data(Qt::AccessibleDescriptionRole), QVariant());
    }
}
Esempio n. 19
0
void
mail_item_model::create_row(mail_msg* msg, QList<QStandardItem*>& items)
{
  bool bold = ((msg->status() & mail_msg::statusRead)==0);
  QStandardItem* isubject = new QStandardItem(msg->Subject());
  if (bold) {
    QFont f=isubject->font();
    f.setBold(true);
    isubject->setFont(f);
  }
  // store mail_msg* into the data of the first item (mail's subject at column 0)
  QVariant v;
  v.setValue(msg);
  isubject->setData(v, mail_item_model::mail_msg_role);

  QStandardItem* ifrom = new QStandardItem();
  if (m_display_sender_mode!="name" || msg->sender_name().isEmpty())
    ifrom->setText(msg->From());
  else
    ifrom->setText(msg->sender_name());
  
  if (bold) {
    QFont f=ifrom->font();
    f.setBold(true);
    ifrom->setFont(f);
  }

  items.append(isubject);
  items.append(ifrom);
  QIcon* icon = icon_status(msg->status());
  if (icon)
    items.append(new QStandardItem(*icon,"")); // status
  else
    items.append(new QStandardItem()); // empty (shouldn't happen)

   // priority (number)
  QStandardItem* ipri = new QStandardItem();
  if (msg->priority()!=0)
    ipri->setText(QString("%1").arg(msg->priority()));
  if (bold) {
    QFont f=ipri->font();
    f.setBold(true);
    ipri->setFont(f);
  }
  items.append(ipri);

  // Attachment
  flag_item* a_item;
  if (msg->has_attachments()) {
    a_item = new flag_item(STATUS_ICON(FT_ICON16_ATTACH));
    a_item->setData(QVariant(true));
  }
  else {
    a_item = new flag_item();
    a_item->setData(QVariant(false));
  }
  items.append(a_item);

  // Note
  flag_item* n_item;
  if (msg->has_note()) {
    n_item = new flag_item(STATUS_ICON(FT_ICON16_EDIT_NOTE));
    n_item->setData(QVariant(true));
  }
  else {
    n_item = new flag_item();
    n_item->setData(QVariant(false));
  }
  items.append(n_item);

  // Date
  date_item* idate = new date_item(msg->msg_date(), m_date_format);
  if (bold) {
    QFont f=idate->font();
    f.setBold(true);
    idate->setFont(f);
  }
  items.append(idate);

  QStandardItem* irecipient = new QStandardItem();
  QList<QString> emails;
  QList<QString> names;
  QString recipients;
  mail_address::ExtractAddresses(msg->recipients(), emails, names);
  QList<QString>::const_iterator iter1 = emails.begin();
  QList<QString>::const_iterator iter2 = names.begin();
  for (; iter1!=emails.end() && iter2!=names.end(); ++iter1,++iter2) {
    if (!recipients.isEmpty())
      recipients.append(", ");
    if (iter2->isEmpty())
      recipients.append(*iter1);
    else
      recipients.append(*iter2);
  }
  
  irecipient->setText(recipients);
  if (bold) {
    QFont f=irecipient->font();
    f.setBold(true);
    irecipient->setFont(f);
  }
  items.append(irecipient);
}