本文整理汇总了C++中QListWidgetItem::setData方法的典型用法代码示例。如果您正苦于以下问题:C++ QListWidgetItem::setData方法的具体用法?C++ QListWidgetItem::setData怎么用?C++ QListWidgetItem::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QListWidgetItem
的用法示例。
在下文中一共展示了QListWidgetItem::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printPdf
void DrawingView::printPdf()
{
Gui::FileOptionsDialog dlg(this, 0);
dlg.setFileMode(QFileDialog::AnyFile);
dlg.setAcceptMode(QFileDialog::AcceptSave);
dlg.setWindowTitle(tr("Export PDF"));
dlg.setFilters(QStringList() << tr("PDF file (*.pdf)"));
QGridLayout *gridLayout;
QGridLayout *formLayout;
QGroupBox *groupBox;
QListWidget *listWidget;
QListWidgetItem* item;
QWidget *form = new QWidget(&dlg);
form->resize(40, 300);
formLayout = new QGridLayout(form);
groupBox = new QGroupBox(form);
gridLayout = new QGridLayout(groupBox);
listWidget = new QListWidget(groupBox);
gridLayout->addWidget(listWidget, 0, 0, 1, 1);
formLayout->addWidget(groupBox, 0, 0, 1, 1);
groupBox->setTitle(tr("Page sizes"));
item = new QListWidgetItem(tr("A0"), listWidget);
item->setData(Qt::UserRole, QVariant(QPrinter::A0));
item = new QListWidgetItem(tr("A1"), listWidget);
item->setData(Qt::UserRole, QVariant(QPrinter::A1));
item = new QListWidgetItem(tr("A2"), listWidget);
item->setData(Qt::UserRole, QVariant(QPrinter::A2));
item = new QListWidgetItem(tr("A3"), listWidget);
item->setData(Qt::UserRole, QVariant(QPrinter::A3));
item = new QListWidgetItem(tr("A4"), listWidget);
item->setData(Qt::UserRole, QVariant(QPrinter::A4));
item = new QListWidgetItem(tr("A5"), listWidget);
item->setData(Qt::UserRole, QVariant(QPrinter::A5));
int index = 4; // by default A4
for (int i=0; i<listWidget->count(); i++) {
if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_pageSize) {
index = i;
break;
}
}
listWidget->item(index)->setSelected(true);
dlg.setOptionsWidget(Gui::FileOptionsDialog::ExtensionRight, form, false);
if (dlg.exec() == QDialog::Accepted) {
Gui::WaitCursor wc;
QString filename = dlg.selectedFiles().front();
QPrinter printer(QPrinter::HighResolution);
printer.setFullPage(true);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(filename);
printer.setOrientation(m_orientation);
QList<QListWidgetItem*> items = listWidget->selectedItems();
if (items.size() == 1) {
int AX = items.front()->data(Qt::UserRole).toInt();
printer.setPaperSize(QPrinter::PageSize(AX));
}
print(&printer);
}
}
示例2: setLayer
void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer )
{
if ( layer == mCurrentLayer )
return;
if ( mCurrentLayer )
{
disconnect( mCurrentLayer, SIGNAL( styleChanged() ), this, SLOT( updateCurrentWidgetLayer() ) );
}
if ( !layer || !layer->isSpatial() )
{
mLayerCombo->setLayer( nullptr );
mStackedWidget->setCurrentIndex( mNotSupportedPage );
mLastStyleXml.clear();
mCurrentLayer = nullptr;
return;
}
bool sameLayerType = false;
if ( mCurrentLayer )
{
sameLayerType = mCurrentLayer->type() == layer->type();
}
mCurrentLayer = layer;
mUndoWidget->setUndoStack( layer->undoStackStyles() );
connect( mCurrentLayer, SIGNAL( styleChanged() ), this, SLOT( updateCurrentWidgetLayer() ) );
int lastPage = mOptionsListWidget->currentIndex().row();
mOptionsListWidget->blockSignals( true );
mOptionsListWidget->clear();
mUserPages.clear();
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QListWidgetItem* symbolItem = new QListWidgetItem( QgsApplication::getThemeIcon( "propertyicons/symbology.svg" ), QString() );
symbolItem->setData( Qt::UserRole, Symbology );
symbolItem->setToolTip( tr( "Symbology" ) );
mOptionsListWidget->addItem( symbolItem );
QListWidgetItem* labelItem = new QListWidgetItem( QgsApplication::getThemeIcon( "labelingSingle.svg" ), QString() );
labelItem->setData( Qt::UserRole, VectorLabeling );
labelItem->setToolTip( tr( "Labels" ) );
mOptionsListWidget->addItem( labelItem );
}
else if ( layer->type() == QgsMapLayer::RasterLayer )
{
QListWidgetItem* symbolItem = new QListWidgetItem( QgsApplication::getThemeIcon( "propertyicons/symbology.svg" ), QString() );
symbolItem->setData( Qt::UserRole, Symbology );
symbolItem->setToolTip( tr( "Symbology" ) );
mOptionsListWidget->addItem( symbolItem );
QListWidgetItem* transparencyItem = new QListWidgetItem( QgsApplication::getThemeIcon( "propertyicons/transparency.png" ), QString() );
transparencyItem->setToolTip( tr( "Transparency" ) );
transparencyItem->setData( Qt::UserRole, RasterTransparency );
mOptionsListWidget->addItem( transparencyItem );
if ( static_cast<QgsRasterLayer*>( layer )->dataProvider()->capabilities() & QgsRasterDataProvider::Size )
{
QListWidgetItem* histogramItem = new QListWidgetItem( QgsApplication::getThemeIcon( "propertyicons/histogram.png" ), QString() );
histogramItem->setData( Qt::UserRole, RasterHistogram );
mOptionsListWidget->addItem( histogramItem );
histogramItem->setToolTip( tr( "Histogram" ) );
}
}
Q_FOREACH ( QgsMapLayerConfigWidgetFactory* factory, mPageFactories )
{
if ( factory->supportsStyleDock() && factory->supportsLayer( layer ) )
{
QListWidgetItem* item = new QListWidgetItem( factory->icon(), QString() );
item->setToolTip( factory->title() );
mOptionsListWidget->addItem( item );
int row = mOptionsListWidget->row( item );
mUserPages[row] = factory;
}
}
QListWidgetItem* historyItem = new QListWidgetItem( QgsApplication::getThemeIcon( "mActionHistory.svg" ), QString() );
historyItem->setData( Qt::UserRole, History );
historyItem->setToolTip( tr( "History" ) );
mOptionsListWidget->addItem( historyItem );
mOptionsListWidget->blockSignals( false );
if ( sameLayerType )
{
mOptionsListWidget->setCurrentRow( lastPage );
}
else
{
mOptionsListWidget->setCurrentRow( 0 );
}
mStackedWidget->setCurrentIndex( 1 );
QString errorMsg;
QDomDocument doc( "style" );
mLastStyleXml = doc.createElement( "style" );
doc.appendChild( mLastStyleXml );
mCurrentLayer->writeStyle( mLastStyleXml, doc, errorMsg );
}
示例3: QListWidget
/************************************************
* Widget Listing:
* Creation of the list of drawed lovely buttons
************************************************/
WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
: QListWidget( _parent )
{
/* We need the parent to know the options checked */
parent = qobject_cast<ToolbarEditDialog *>(_parent);
assert( parent );
/* Normal options */
setViewMode( QListView::ListMode );
setTextElideMode( Qt::ElideNone );
setDragEnabled( true );
int icon_size = fontMetrics().height();
setIconSize( QSize( icon_size * 2, icon_size ) );
/* All the buttons do not need a special rendering */
for( int i = 0; i < BUTTON_MAX; i++ )
{
QListWidgetItem *widgetItem = new QListWidgetItem( this );
widgetItem->setText( qtr( nameL[i] ) );
widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
widgetItem->setIcon( QIcon( iconL[i] ) );
widgetItem->setData( Qt::UserRole, QVariant( i ) );
widgetItem->setToolTip( widgetItem->text() );
addItem( widgetItem );
}
/* Spacers are yet again a different thing */
QListWidgetItem *widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space.svg" ),
qtr( "Spacer" ), this );
widgetItem->setData( Qt::UserRole, WIDGET_SPACER );
widgetItem->setToolTip( widgetItem->text() );
widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
addItem( widgetItem );
widgetItem = new QListWidgetItem( QIcon( ":/toolbar/space.svg" ),
qtr( "Expanding Spacer" ), this );
widgetItem->setData( Qt::UserRole, WIDGET_SPACER_EXTEND );
widgetItem->setToolTip( widgetItem->text() );
widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
addItem( widgetItem );
/**
* For all other widgets, we create then, do a pseudo rendering in
* a pixmaps for the view, and delete the object
*
* A lot of code is retaken from the Abstract, but not exactly...
* So, rewrite.
* They are better ways to deal with this, but I doubt that this is
* necessary. If you feel like you have the time, be my guest.
* --
* jb
**/
for( int i = SPLITTER; i < SPECIAL_MAX; i++ )
{
QWidget *widget = NULL;
QListWidgetItem *widgetItem = new QListWidgetItem;
widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
switch( i )
{
case SPLITTER:
{
QFrame *line = new QFrame( this );
line->setFrameShape( QFrame::VLine );
line->setFrameShadow( QFrame::Raised );
line->setLineWidth( 0 ); line->setMidLineWidth( 1 );
widget = line;
}
widgetItem->setText( qtr("Splitter") );
break;
case INPUT_SLIDER:
{
SeekSlider *slider = new SeekSlider( p_intf, Qt::Horizontal, this );
widget = slider;
}
widgetItem->setText( qtr("Time Slider") );
break;
case VOLUME:
{
SoundWidget *snd = new SoundWidget( this, p_intf,
parent->getOptions() & WIDGET_SHINY );
widget = snd;
}
widgetItem->setText( qtr("Volume") );
break;
case VOLUME_SPECIAL:
{
QListWidgetItem *widgetItem = new QListWidgetItem( this );
widgetItem->setText( qtr("Small Volume") );
widgetItem->setIcon( QIcon( ":/toolbar/volume-medium.svg" ) );
widgetItem->setData( Qt::UserRole, QVariant( i ) );
addItem( widgetItem );
}
continue;
case TIME_LABEL:
{
QLabel *timeLabel = new QLabel( "12:42/2:12:42", this );
//.........这里部分代码省略.........
示例4: BaseFilterWidget
StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *transferList)
: BaseFilterWidget(parent, transferList)
{
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated
, this, &StatusFilterWidget::updateTorrentNumbers);
// Add status filters
QListWidgetItem *all = new QListWidgetItem(this);
all->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the status filter")));
all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.svg"));
QListWidgetItem *downloading = new QListWidgetItem(this);
downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading (0)")));
downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.svg"));
QListWidgetItem *seeding = new QListWidgetItem(this);
seeding->setData(Qt::DisplayRole, QVariant(tr("Seeding (0)")));
seeding->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.svg"));
QListWidgetItem *completed = new QListWidgetItem(this);
completed->setData(Qt::DisplayRole, QVariant(tr("Completed (0)")));
completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/completed.svg"));
QListWidgetItem *resumed = new QListWidgetItem(this);
resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed (0)")));
resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.svg"));
QListWidgetItem *paused = new QListWidgetItem(this);
paused->setData(Qt::DisplayRole, QVariant(tr("Paused (0)")));
paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.svg"));
QListWidgetItem *active = new QListWidgetItem(this);
active->setData(Qt::DisplayRole, QVariant(tr("Active (0)")));
active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.svg"));
QListWidgetItem *inactive = new QListWidgetItem(this);
inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive (0)")));
inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.svg"));
QListWidgetItem *errored = new QListWidgetItem(this);
errored->setData(Qt::DisplayRole, QVariant(tr("Errored (0)")));
errored->setData(Qt::DecorationRole, QIcon(":/icons/skin/error.svg"));
const Preferences *const pref = Preferences::instance();
setCurrentRow(pref->getTransSelFilter(), QItemSelectionModel::SelectCurrent);
toggleFilter(pref->getStatusFilterState());
}
示例5: addPoint
void TriangulationSidebar::addPoint(QPointF point) {
QString str=QString::number(point.y())+", "+QString::number(point.x());
QListWidgetItem *item = new QListWidgetItem(str);
item->setData(Qt::UserRole, QVariant(point));
pointsListWidget->addItem(item);
}
示例6: parseXML
//XML
//Parse XML into tasklist form
int TaskList_Main::parseXML(QDomDocument &domTree){
QDomElement set = domTree.namedItem("listset").toElement();
QMessageBox msgBox;
//If tree doesn't exist, stop
if(set.isNull()){
msgBox.setText("No <listset> element at top level");
msgBox.setWindowTitle("Erorr parsing XML");
msgBox.exec();
return -1;
}
//Iterate through all "list" items
QDomElement n = set.firstChildElement("list");
for( ; !n.isNull(); n = n.nextSiblingElement("list")){
emit createList(n.namedItem("list_title").toElement().text());
delListAction->setEnabled(true);
printAction->setEnabled(true);
printAllAction->setEnabled(true);
//Iterate through all "task" items part of "list"
QDomElement o = n.firstChildElement("task");
for( ; !o.isNull(); o = o.nextSiblingElement("task")){
my_listwidget *currList = notePane->listMap[notePane->currList];
QListWidgetItem *currItem;
QString tempStr;
//If task is 'main' (not subtext/subnote)
if(o.attribute("task_type") == "main"){
//Change task name
notePane->addItemAction(o.namedItem("task_title").toElement().text(), false);
currItem = currList->currentItem();
//Change task check state
tempStr = o.namedItem("task_check").toElement().text();
if(tempStr == "unchecked")
currItem->setCheckState(Qt::Unchecked);
else if (tempStr == "checked")
currItem->setCheckState(Qt::Checked);
else if (tempStr == "part_check")
currItem->setCheckState(Qt::PartiallyChecked);
else{
msgBox.setText("Unknown check state");
msgBox.setWindowTitle("Erorr parsing XML");
msgBox.exec();
return -1;
}
//Change task subnote
currItem->setData(32, QVariant(
o.namedItem("task_note").toElement().text()));
//Change if task subnote is displayed
tempStr = o.namedItem("task_display").toElement().text();
if(tempStr == "false"){
currItem->setData(33, QVariant(false));
currItem->setData(35, QVariant(false));
}
else if(tempStr == "true"){
currItem->setData(33, QVariant(true));
currItem->setData(35, QVariant(true));
}
else{
msgBox.setText("Unknown bool type - display");
msgBox.setWindowTitle("Erorr parsing XML");
msgBox.exec();
return -1;
}
//Change the task due date
tempStr = o.namedItem("task_date").toElement().text();
qDebug((const char *)tempStr.toAscii().data());
QDate tempDate;
int year = tempStr.left(4).toInt();
int month = tempStr.mid(5, 2).toInt();
int day = tempStr.right(2).toInt();
tempDate.setDate(year, month, day);
if(!tempDate.isValid()){
msgBox.setText("Unknown date type");
msgBox.setWindowTitle("Erorr parsing XML");
msgBox.exec();
return -1;
}
currItem->setData(34, QVariant(tempDate));
//Change the task font
tempStr = o.namedItem("task_font").toElement().text();
QFont tempFont;
if(!tempFont.fromString(tempStr)){
msgBox.setText("Unknown font");
msgBox.setWindowTitle("Erorr parsing XML");
msgBox.exec();
return -1;
}
currItem->setFont(tempFont);
}
//Else if it is a subtext/subnote for a 'main'
else if (o.attribute("task_type") == "sub"){
//.........这里部分代码省略.........
示例7: fi
TextPalette::TextPalette(QWidget* parent)
: QWidget(parent)
{
setWindowFlags(Qt::Tool);
setupUi(this);
pCommon = new Palette;
pCommon->setMag(0.8);
pCommon->setGrid(33, 60);
pCommon->setReadOnly(true);
pSmufl = new Palette;
pSmufl->setMag(0.8);
pSmufl->setGrid(33, 60);
pSmufl->setReadOnly(true);
pUnicode = new Palette;
pUnicode->setMag(0.8);
pUnicode->setGrid(33, 60);
pUnicode->setReadOnly(true);
PaletteScrollArea* psa = new PaletteScrollArea(pCommon);
psa->setRestrictHeight(false);
tabWidget->clear();
tabWidget->addTab(psa, tr("Common Symbols"));
psa = new PaletteScrollArea(pSmufl);
psa->setRestrictHeight(false);
QSplitter* ws = new QSplitter;
lws = new QListWidget;
ScoreFont* scoreFont = ScoreFont::fontFactory("Bravura");
QFile fi(scoreFont->fontPath() + "ranges.json");
if (!fi.open(QIODevice::ReadOnly))
qDebug("ScoreFont: open ranges file <%s> failed", qPrintable(fi.fileName()));
QJsonParseError error;
QJsonObject o = QJsonDocument::fromJson(fi.readAll(), &error).object();
if (error.error != QJsonParseError::NoError)
qDebug("Json parse error in <%s>(offset: %d): %s", qPrintable(fi.fileName()),
error.offset, qPrintable(error.errorString()));
int i = 0;
QStringList smuflRangeNames;
for (auto s : o.keys()) {
QJsonObject range = o.value(s).toObject();
QString desc = range.value("description").toString();
QJsonArray glyphs = range.value("glyphs").toArray();
if (glyphs.size() > 0) {
for (QJsonValue g : glyphs)
smuflMap[i].append(g.toString());
smuflRangeNames.append(desc);
i++;
}
}
lws->addItems(smuflRangeNames);
lws->setCurrentRow(0);
ws->addWidget(lws);
ws->addWidget(psa);
tabWidget->addTab(ws, tr("Musical Symbols"));
psa = new PaletteScrollArea(pUnicode);
psa->setRestrictHeight(false);
QSplitter* wu = new QSplitter;
lwu = new QListWidget;
lwu->setSortingEnabled(true);
for (i = 0; i < unicodeRangeNames.length(); i++) {
QListWidgetItem* newItem = new QListWidgetItem(qApp->translate("accidental", unicodeRangeNames.at(i).toUtf8().constData()));
newItem->setData(Qt::UserRole, i);
lwu->addItem(newItem);
if (i == 0)
lwu->setCurrentItem(newItem);
}
wu->addWidget(lwu);
wu->addWidget(psa);
tabWidget->addTab(wu, tr("Unicode Symbols"));
connect(lws, SIGNAL(currentRowChanged(int)), SLOT(populateSmufl()));
connect(lwu, SIGNAL(currentRowChanged(int)), SLOT(populateUnicode()));
// others are done in setFont
populateSmufl();
setFocusPolicy(Qt::NoFocus);
}
示例8: addDirectoryToPreview
int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
{
//go through all files of a directory
QDir directory( path );
if ( !directory.exists() || !directory.isReadable() )
{
return 1; //error
}
QFileInfoList fileList = directory.entryInfoList( QDir::Files );
QFileInfoList::const_iterator fileIt = fileList.constBegin();
QProgressDialog progress( "Adding Icons...", "Abort", 0, fileList.size() - 1, this );
//cancel button does not seem to work properly with modal dialog
//progress.setWindowModality(Qt::WindowModal);
int counter = 0;
for ( ; fileIt != fileList.constEnd(); ++fileIt )
{
progress.setLabelText( tr( "Creating icon for file %1" ).arg( fileIt->fileName() ) );
progress.setValue( counter );
QCoreApplication::processEvents();
if ( progress.wasCanceled() )
{
break;
}
QString filePath = fileIt->absoluteFilePath();
//test if file is svg or pixel format
bool fileIsPixel = false;
bool fileIsSvg = testSvgFile( filePath );
if ( !fileIsSvg )
{
fileIsPixel = testImageFile( filePath );
}
//exclude files that are not svg or image
if ( !fileIsSvg && !fileIsPixel )
{
++counter; continue;
}
QListWidgetItem * listItem = new QListWidgetItem( mPreviewListWidget );
listItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
if ( fileIsSvg )
{
QIcon icon( filePath );
listItem->setIcon( icon );
}
else //for pixel formats: create icon from scaled pixmap
{
QPixmap iconPixmap( filePath );
if ( iconPixmap.isNull() )
{
++counter; continue; //unknown file format or other problem
}
//set pixmap hardcoded to 30/30, same as icon size for mPreviewListWidget
QPixmap scaledPixmap( iconPixmap.scaled( QSize( 30, 30 ), Qt::KeepAspectRatio ) );
QIcon icon( scaledPixmap );
listItem->setIcon( icon );
}
listItem->setText( "" );
//store the absolute icon file path as user data
listItem->setData( Qt::UserRole, fileIt->absoluteFilePath() );
++counter;
}
return 0;
}
示例9: if
//.........这里部分代码省略.........
QComboBox *cb = comboBox( editor, parent );
if ( cb )
{
if ( data.mAllowNull )
{
QSettings settings;
cb->addItem( tr( "(no selection)" ), settings.value( "qgis/nullValue", "NULL" ).toString() );
}
for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ )
{
if ( data.mOrderByValue )
cb->addItem( it.key(), it.value() );
else
cb->addItem( it.value(), it.key() );
}
myWidget = cb;
}
}
else
{
QListWidget *lw = listWidget( editor, parent );
if ( lw )
{
QStringList checkList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( "," );
for ( QMap< QString, QString >::const_iterator it = map.begin(); it != map.end(); it++ )
{
QListWidgetItem *item;
if ( data.mOrderByValue )
{
item = new QListWidgetItem( it.key() );
item->setData( Qt::UserRole, it.value() );
item->setCheckState( checkList.contains( it.value() ) ? Qt::Checked : Qt::Unchecked );
}
else
{
item = new QListWidgetItem( it.value() );
item->setData( Qt::UserRole, it.key() );
item->setCheckState( checkList.contains( it.key() ) ? Qt::Checked : Qt::Unchecked );
}
lw->addItem( item );
}
myWidget = lw;
}
}
}
break;
case QgsVectorLayer::Classification:
{
QMap<QString, QString> classes;
const QgsUniqueValueRenderer *uvr = dynamic_cast<const QgsUniqueValueRenderer *>( vl->renderer() );
if ( uvr )
{
const QList<QgsSymbol *> symbols = uvr->symbols();
for ( int i = 0; i < symbols.size(); i++ )
{
QString label = symbols[i]->label();
QString name = symbols[i]->lowerValue();
if ( label == "" )
示例10: QDialog
PreferencesDialog::PreferencesDialog(Preferences& preferences, QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint),
m_preferences(preferences)
{
setWindowTitle(tr("Preferences"));
QTabWidget* tabs = new QTabWidget(this);
tabs->addTab(initGeneralTab(), tr("General"));
tabs->addTab(initStatisticsTab(), tr("Statistics"));
tabs->addTab(initToolbarTab(), tr("Toolbar"));
tabs->addTab(initSpellingTab(), tr("Spell Checking"));
tabs->setUsesScrollButtons(false);
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(tabs);
layout->addWidget(buttons);
// Load settings
switch (m_preferences.goalType()) {
case 1:
m_option_time->setChecked(true);
break;
case 2:
m_option_wordcount->setChecked(true);
break;
default:
m_option_none->setChecked(true);
break;
}
m_time->setValue(m_preferences.goalMinutes());
m_wordcount->setValue(m_preferences.goalWords());
m_show_characters->setChecked(m_preferences.showCharacters());
m_show_pages->setChecked(m_preferences.showPages());
m_show_paragraphs->setChecked(m_preferences.showParagraphs());
m_show_words->setChecked(m_preferences.showWords());
switch (m_preferences.pageType()) {
case 1:
m_option_paragraphs->setChecked(true);
break;
case 2:
m_option_words->setChecked(true);
break;
default:
m_option_characters->setChecked(true);
break;
}
m_page_characters->setValue(m_preferences.pageCharacters());
m_page_paragraphs->setValue(m_preferences.pageParagraphs());
m_page_words->setValue(m_preferences.pageWords());
if (m_preferences.accurateWordcount()) {
m_option_accurate_wordcount->setChecked(true);
} else {
m_option_estimate_wordcount->setChecked(true);
}
m_always_center->setChecked(m_preferences.alwaysCenter());
m_block_cursor->setChecked(m_preferences.blockCursor());
m_rich_text->setChecked(m_preferences.richText());
m_smooth_fonts->setChecked(m_preferences.smoothFonts());
m_smart_quotes->setChecked(m_preferences.smartQuotes());
m_double_quotes->setCurrentIndex(m_preferences.doubleQuotes());
m_single_quotes->setCurrentIndex(m_preferences.singleQuotes());
m_typewriter_sounds->setChecked(m_preferences.typewriterSounds());
m_auto_save->setChecked(m_preferences.autoSave());
m_save_positions->setChecked(m_preferences.savePositions());
int style = m_toolbar_style->findData(m_preferences.toolbarStyle());
if (style == -1) {
style = m_toolbar_style->findData(Qt::ToolButtonTextUnderIcon);
}
m_toolbar_style->setCurrentIndex(style);
QStringList actions = m_preferences.toolbarActions();
int pos = 0;
foreach (const QString& action, actions) {
QString text = action;
bool checked = !text.startsWith("^");
if (!checked) {
text.remove(0, 1);
}
QListWidgetItem* item = 0;
if (text != "|") {
int count = m_toolbar_actions->count();
for (int i = pos; i < count; ++i) {
if (m_toolbar_actions->item(i)->data(Qt::UserRole).toString() == text) {
item = m_toolbar_actions->takeItem(i);
break;
}
}
} else if (checked) {
item = new QListWidgetItem(QString(20, QChar('-')));
item->setData(Qt::UserRole, "|");
//.........这里部分代码省略.........
示例11: QDialog
BootSelectionDialog::BootSelectionDialog(const QString &defaultPartition, QWidget *parent) :
QDialog(parent),
_countdown(OS_SELECTION_TIMEOUT+1),
ui(new Ui::BootSelectionDialog)
{
setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
ui->setupUi(this);
QRect s = QApplication::desktop()->screenGeometry();
if (s.height() < 500)
resize(s.width()-10, s.height()-100);
QDir dir;
dir.mkdir("/settings");
if (QProcess::execute("mount -o remount,ro /settings") != 0
&& QProcess::execute("mount -t ext4 -o ro " SETTINGS_PARTITION " /settings") != 0)
{
QMessageBox::critical(this, tr("Cannot display boot menu"), tr("Error mounting settings partition"));
return;
}
/* Also mount /dev/mmcblk0p1 as it may contain icons we need */
if (QProcess::execute("mount -t vfat -o ro /dev/mmcblk0p1 /mnt") != 0)
{
/* Not fatal if this fails */
}
QVariantList installed_os = Json::loadFromFile("/settings/installed_os.json").toList();
QSize currentsize = ui->list->iconSize();
foreach (QVariant v, installed_os)
{
QVariantMap m = v.toMap();
QString iconfilename = m.value("icon").toString();
QIcon icon;
if (!iconfilename.isEmpty() && QFile::exists(iconfilename))
{
icon = QIcon(iconfilename);
QList<QSize> avs = icon.availableSizes();
if (avs.isEmpty())
{
/* Icon file corrupt */
icon = QIcon();
}
else
{
QSize iconsize = avs.first();
if (iconsize.width() > currentsize.width() || iconsize.height() > currentsize.height())
{
/* Make all icons as large as the largest icon we have */
currentsize = QSize(qMax(iconsize.width(), currentsize.width()),qMax(iconsize.height(), currentsize.height()));
ui->list->setIconSize(currentsize);
}
}
}
if (canBootOs(m.value("name").toString(), m))
{
QListWidgetItem *item = new QListWidgetItem(icon, m.value("name").toString()+"\n"+m.value("description").toString(), ui->list);
item->setData(Qt::UserRole, m);
}
}
示例12: sectionEnabled
ThymioFlasherDialog::ThymioFlasherDialog()
{
typedef std::map<int, std::pair<std::string, std::string> > PortsMap;
const PortsMap ports = SerialPortEnumerator::getPorts();
QSettings settings;
// Create the gui ...
setWindowTitle(tr("Thymio Firmware Updater"));
resize(600,500);
QVBoxLayout* mainLayout = new QVBoxLayout(this);
// make sure the port list is enabled only if serial ports are found
unsigned sectionEnabled(ports.empty() ? 1 : 0);
// serial port
serialGroupBox = new QGroupBox(tr("Serial connection"));
serialGroupBox->setCheckable(true);
QHBoxLayout* serialLayout = new QHBoxLayout();
serial = new QListWidget();
bool serialPortSet(false);
for (PortsMap::const_iterator it = ports.begin(); it != ports.end(); ++it)
{
const QString text(it->second.second.c_str());
QListWidgetItem* item = new QListWidgetItem(text);
item->setData(Qt::UserRole, QVariant(QString::fromUtf8(it->second.first.c_str())));
serial->addItem(item);
if (it->second.second.compare(0,9,"Thymio-II") == 0)
{
serial->setCurrentItem(item);
serialPortSet = true;
}
}
if (sectionEnabled == 0 && !serialPortSet)
sectionEnabled = 1;
serialGroupBox->setChecked(sectionEnabled == 0);
serial->setSelectionMode(QAbstractItemView::SingleSelection);
serialLayout->addWidget(serial);
connect(serial, SIGNAL(itemSelectionChanged()), SLOT(setupFlashButtonState()));
serialGroupBox->setLayout(serialLayout);
connect(serialGroupBox, SIGNAL(clicked()), SLOT(serialGroupChecked()));
mainLayout->addWidget(serialGroupBox);
// custom target
customGroupBox = new QGroupBox(tr("Custom connection"));
customGroupBox->setCheckable(true);
customGroupBox->setChecked(sectionEnabled == 1);
QHBoxLayout* customLayout = new QHBoxLayout();
QLineEdit* custom = new QLineEdit(settings.value("custom target", ASEBA_DEFAULT_TARGET).toString());
customLayout->addWidget(custom);
customGroupBox->setLayout(customLayout);
connect(customGroupBox, SIGNAL(clicked()), SLOT(customGroupChecked()));
mainLayout->addWidget(customGroupBox);
// file selector
QGroupBox* fileGroupBox = new QGroupBox(tr("Firmware file"));
QHBoxLayout *fileLayout = new QHBoxLayout();
lineEdit = new QLineEdit(this);
fileButton = new QPushButton(tr("Select..."), this);
fileLayout->addWidget(fileButton);
fileLayout->addWidget(lineEdit);
fileGroupBox->setLayout(fileLayout);
mainLayout->addWidget(fileGroupBox);
// progress bar
progressBar = new QProgressBar(this);
progressBar->setValue(0);
progressBar->setRange(0, 100);
mainLayout->addWidget(progressBar);
// flash and quit buttons
QHBoxLayout *flashLayout = new QHBoxLayout();
flashButton = new QPushButton(tr("Update"), this);
flashButton->setEnabled(false);
flashLayout->addWidget(flashButton);
quitButton = new QPushButton(tr("Quit"), this);
flashLayout->addWidget(quitButton);
mainLayout->addItem(flashLayout);
// connections
connect(fileButton, SIGNAL(clicked()), SLOT(openFile()));
connect(flashButton, SIGNAL(clicked()), SLOT(doFlash()));
connect(quitButton, SIGNAL(clicked()), SLOT(close()));
connect(&flashFutureWatcher, SIGNAL(finished()), SLOT(flashFinished()));
show();
}
示例13: f
CWPosSel::CWPosSel(QWidget *parent, mapView_t *view) :
//////////////////////////////////////////////////////
QDialog(parent),
ui(new Ui::CWPosSel)
{
ui->setupUi(this);
m_earthTools.setCacheFolder(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/cache");
connect(&m_earthTools, SIGNAL(sigDone(bool,double,int)), this, SLOT(slotETDone(bool,double,int)));
connect(&m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotLocationDone(QNetworkReply*)));
SkFile f(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/locations/locations.dat");
if (f.open(SkFile::ReadOnly | SkFile::Text))
{
QString str;
QStringList l;
do
{
str = f.readLine();
if (str.isEmpty() || str.startsWith("\n"))
break;
l = str.split("|");
if (l.count() != 5)
{
qDebug("CWPosSel read line fail!");
continue;
}
location_t *loc = new location_t;
loc->name = l.at(0);
loc->lon = l.at(1).toDouble();
loc->lat = l.at(2).toDouble();
loc->alt = l.at(3).toDouble();
loc->tz = l.at(4).toDouble();
m_tList.append(loc);
QListWidgetItem *w = new QListWidgetItem(loc->name, NULL, 1);
w->setData(Qt::UserRole, (qint64)loc);
ui->listWidget->addItem(w);
} while (1);
f.close();
}
ui->spinBox_8->setValue(view->geo.temp);
ui->spinBox_9->setValue(view->geo.press);
ui->checkBox->setChecked(!view->geo.useAtmRefraction);
ui->cb_tempType->addItem("C");
ui->cb_tempType->addItem("F");
ui->cb_tempType->setCurrentIndex(view->geo.tempType);
location_t loc;
loc.name = view->geo.name;
loc.lon = R2D(view->geo.lon);
loc.lat = R2D(view->geo.lat);
loc.alt = view->geo.alt;
loc.tz = view->geo.tzo * 24.0;
ui->doubleSpinBox_4->setValue(view->geo.sdlt * 24.0);
m_view = view;
setData(&loc);
QShortcut *sh1 = new QShortcut(QKeySequence(Qt::Key_Delete), ui->listWidget, 0, 0, Qt::WidgetShortcut);
connect(sh1, SIGNAL(activated()), this, SLOT(slotDeleteItem()));
ui->widget->setModel((QSortFilterProxyModel *)ui->listWidget->model(), 0);
connect(ui->widget, SIGNAL(sigSetSelection(QModelIndex&)), this, SLOT(slotSelChange(QModelIndex&)));
SkFile file(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/data/locations/home.dat");
if (file.open(QFile::ReadOnly))
{
QDataStream ds(&file);
int count;
ds >> count;
for (int i = 0; i < count; i++)
{
location_t loc;
ds >> loc.name;
ds >> loc.alt;
ds >> loc.lat;
ds >> loc.lon;
ds >> loc.tz;
QVariant var;
var.setValue(loc);
ui->cb_home->addItem(loc.name, var);
}
}
示例14: QDialog
ImportList::ImportList(QWidget *parent) :
QDialog(parent),
ui(new Ui::ImportList), selectedFile(NULL)
{
ui->setupUi(this);
//Set up preview table
ui->twPreview->setHidden(true);
ui->pbRefresh->setHidden(true);
connect(ui->gbPreview, SIGNAL(clicked()), this, SLOT(togglePreview()));
connect(ui->pbCancel, SIGNAL(clicked()), this, SLOT(reject()));
connect(ui->pbImport, SIGNAL(clicked()), this, SLOT(import()));
//Browse File and Preview Related
connect(ui->pbBrowse, SIGNAL(clicked()), this, SLOT(browseListFile()));
connect(ui->leFilePath, SIGNAL(editingFinished()), this, SLOT(reloadSelectedFile()));
connect(ui->leFilePath, SIGNAL(returnPressed()), this, SLOT(reloadSelectedFile()));
connect(ui->pbRefresh, SIGNAL(clicked()), this, SLOT(reloadSelectedFile()));
//Column Management Related
connect(ui->pbAdd, SIGNAL(clicked()), this, SLOT(addSelectedColumns()));
connect(ui->pbRemove, SIGNAL(clicked()), this, SLOT(removeSelectedColumns()));
connect(ui->pbMoveUp, SIGNAL(clicked()), this, SLOT(moveSelectedUp()));
connect(ui->pbMoveDown, SIGNAL(clicked()), this, SLOT(moveSelectedDown()));
QListWidgetItem *item = new QListWidgetItem("Name", ui->lwAvailableColumns);
item->setToolTip("Movie Title; Can contain any character");
item->setData(Qt::UserRole, QVariant::fromValue(UserRoleData(QString("\"(.*)\""), UserRoleData::Name)));
ui->lwAvailableColumns->addItem(item);
item = new QListWidgetItem("Year", ui->lwAvailableColumns);
item->setToolTip("Year when the movie came out; format: YYYY");
item->setData(Qt::UserRole, QVariant::fromValue(UserRoleData(QString("([0-9]*)"), UserRoleData::Year)));
ui->lwAvailableColumns->addItem(item);
item = new QListWidgetItem("Quality", ui->lwAvailableColumns);
item->setToolTip("Should be one of the following string: \"Xvid\", \"BDRIP\", \"720p\", or \"1080p\"");
item->setData(Qt::UserRole, QVariant::fromValue(UserRoleData(QString("\"(.*)\""), UserRoleData::Quality)));
ui->lwAvailableColumns->addItem(item);
item = new QListWidgetItem("IMDB Link", ui->lwAvailableColumns);
item->setToolTip("Valid link to IMDB Page.");
item->setData(Qt::UserRole, QVariant::fromValue(UserRoleData(QString("\"(.*)\""), UserRoleData::IMDB)));
ui->lwAvailableColumns->addItem(item);
QStringList selectedColumns;
m_settings.beginGroup(IMPORT_GROUP);
int size = m_settings.beginReadArray(SELECTED_COLUMNS_ARRAY);
for(int i = 0; i < size; i++)
{
m_settings.setArrayIndex(i);
selectedColumns.push_front(m_settings.value(SELECTED_COLUMNS_COLUMN_KEY).toString());
}
m_settings.endArray();
ui->leFilePath->setText(m_settings.value(LAST_SELECTED_FILE_KEY).toString());
reloadSelectedFile();
m_settings.endGroup();
QStringList::iterator itr = selectedColumns.begin();
for(; itr != selectedColumns.end(); ++itr)
{
for(int i = 0; i < ui->lwAvailableColumns->count(); i++)
{
if(ui->lwAvailableColumns->item(i)->text() == *itr)
{
ui->lwColumnOrder->insertItem(0, ui->lwAvailableColumns->takeItem(i));
break;
}
}
}
}
示例15: CreateWidget
//.........这里部分代码省略.........
case EXTENSION_WIDGET_IMAGE:
label = new QLabel( this );
label->setPixmap( QPixmap( qfu( p_widget->psz_text ) ) );
if( p_widget->i_width > 0 )
label->setMaximumWidth( p_widget->i_width );
if( p_widget->i_height > 0 )
label->setMaximumHeight( p_widget->i_height );
label->setScaledContents( true );
p_widget->p_sys_intf = label;
return label;
case EXTENSION_WIDGET_HTML:
textArea = new QTextBrowser( this );
textArea->setOpenExternalLinks( true );
textArea->setHtml( qfu( p_widget->psz_text ) );
p_widget->p_sys_intf = textArea;
return textArea;
case EXTENSION_WIDGET_TEXT_FIELD:
textInput = new QLineEdit( this );
textInput->setText( qfu( p_widget->psz_text ) );
textInput->setReadOnly( false );
textInput->setEchoMode( QLineEdit::Normal );
inputMapper->setMapping( textInput, new WidgetMapper( p_widget ) );
/// @note: maybe it would be wiser to use textEdited here?
CONNECT( textInput, textChanged(const QString &),
inputMapper, map() );
p_widget->p_sys_intf = textInput;
return textInput;
case EXTENSION_WIDGET_PASSWORD:
textInput = new QLineEdit( this );
textInput->setText( qfu( p_widget->psz_text ) );
textInput->setReadOnly( false );
textInput->setEchoMode( QLineEdit::Password );
inputMapper->setMapping( textInput, new WidgetMapper( p_widget ) );
/// @note: maybe it would be wiser to use textEdited here?
CONNECT( textInput, textChanged(const QString &),
inputMapper, map() );
p_widget->p_sys_intf = textInput;
return textInput;
case EXTENSION_WIDGET_CHECK_BOX:
checkBox = new QCheckBox( this );
checkBox->setText( qfu( p_widget->psz_text ) );
checkBox->setChecked( p_widget->b_checked );
clickMapper->setMapping( checkBox, new WidgetMapper( p_widget ) );
CONNECT( checkBox, stateChanged( int ), clickMapper, map() );
p_widget->p_sys_intf = checkBox;
return checkBox;
case EXTENSION_WIDGET_DROPDOWN:
comboBox = new QComboBox( this );
comboBox->setEditable( false );
for( p_value = p_widget->p_values;
p_value != NULL;
p_value = p_value->p_next )
{
comboBox->addItem( qfu( p_value->psz_text ), p_value->i_id );
}
/* Set current item */
if( p_widget->psz_text )
{
int idx = comboBox->findText( qfu( p_widget->psz_text ) );
if( idx >= 0 )
comboBox->setCurrentIndex( idx );
}
selectMapper->setMapping( comboBox, new WidgetMapper( p_widget ) );
CONNECT( comboBox, currentIndexChanged( const QString& ),
selectMapper, map() );
return comboBox;
case EXTENSION_WIDGET_LIST:
list = new QListWidget( this );
list->setSelectionMode( QAbstractItemView::ExtendedSelection );
for( p_value = p_widget->p_values;
p_value != NULL;
p_value = p_value->p_next )
{
QListWidgetItem *item =
new QListWidgetItem( qfu( p_value->psz_text ) );
item->setData( Qt::UserRole, p_value->i_id );
list->addItem( item );
}
selectMapper->setMapping( list, new WidgetMapper( p_widget ) );
CONNECT( list, itemSelectionChanged(),
selectMapper, map() );
return list;
case EXTENSION_WIDGET_SPIN_ICON:
spinIcon = new SpinningIcon( this );
spinIcon->play( p_widget->i_spin_loops );
p_widget->p_sys_intf = spinIcon;
return spinIcon;
default:
msg_Err( p_intf, "Widget type %d unknown", p_widget->type );
return NULL;
}
}