bool QMessageBox::qt_property( int id, int f, QVariant* v)
{
    switch ( id - staticMetaObject()->propertyOffset() ) {
    case 0: switch( f ) {
	case 0: setText(v->asString()); break;
	case 1: *v = QVariant( this->text() ); break;
	case 3: case 4: case 5: break;
	default: return FALSE;
    } break;
    case 1: switch( f ) {
	case 0: setIcon((Icon&)v->asInt()); break;
	case 1: *v = QVariant( (int)this->icon() ); break;
	case 3: case 4: case 5: break;
	default: return FALSE;
    } break;
    case 2: switch( f ) {
	case 0: setIconPixmap(v->asPixmap()); break;
	case 1: if ( this->iconPixmap() ) *v = QVariant( *iconPixmap() ); break;
	case 3: case 4: case 5: break;
	default: return FALSE;
    } break;
    case 3: switch( f ) {
	case 0: setTextFormat((TextFormat&)v->asInt()); break;
	case 1: *v = QVariant( (int)this->textFormat() ); break;
	case 3: case 4: case 5: break;
	default: return FALSE;
    } break;
    default:
	return QDialog::qt_property( id, f, v );
    }
    return TRUE;
}
Example #2
0
void EditPlacemarkDialog::updateIconDialog( const QColor &color )
{
    QPixmap iconPixmap( d->m_iconButton->iconSize().width(),
                        d->m_iconButton->iconSize().height() );
    iconPixmap.fill( color );
    d->m_iconButton->setIcon( QIcon( iconPixmap ) );
}
Example #3
0
void ImageView::setButtonIcon(QPushButton *button, QString fileName, int width, int height)
{
  QPixmap iconPixmap(fileName);
  QIcon buttonIcon(iconPixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation));
  button->setIcon(buttonIcon);
  button->setIconSize(iconPixmap.scaled(width, height).rect().size());
}
Example #4
0
QSize KMultiTabBarTab::computeSizeHint(bool withText) const
{
	// Compute as horizontal first, then flip around if need be.
	QStyleOptionToolButton opt;
	initStyleOption(&opt);

	int hMargin, vMargin;
	computeMargins(&hMargin, &vMargin);

	// Compute interior size, starting from pixmap..
	QPixmap iconPix = iconPixmap();
	QSize size = iconPix.size();

	// Always include text height in computation, to avoid resizing the minor direction
	// when expanding text..
	QSize textSize = fontMetrics().size(0, text());
	size.setHeight(qMax(size.height(), textSize.height()));

	// Pick margins for major/minor direction, depending on orientation
	int majorMargin = isVertical() ? vMargin : hMargin;
	int minorMargin = isVertical() ? hMargin : vMargin;

	size.setWidth (size.width()  + 2*majorMargin);
	size.setHeight(size.height() + 2*minorMargin);

	if (withText)
		// Add enough room for the text, and an extra major margin.
		size.setWidth(size.width() + textSize.width() + majorMargin);

	// flip time?
	if (isVertical())
		return QSize(size.height(), size.width());
	else
		return size;
}
Example #5
0
void KMultiTabBarTab::initStyleOption(QStyleOptionToolButton* opt) const
{
	opt->initFrom(this);

	// Setup icon..
	if (!icon().isNull()) {
		opt->iconSize = iconPixmap().size();
		opt->icon     = icon();
	}

	// Should we draw text?
	if (shouldDrawText())
		opt->text = text();

	opt->state |= QStyle::State_AutoRaise;
	if (underMouse())
		opt->state |= QStyle::State_MouseOver | QStyle::State_Raised;

	if (isChecked())
		opt->state |= QStyle::State_Sunken | QStyle::State_On;

	opt->font = font();
	opt->toolButtonStyle = shouldDrawText() ? Qt::ToolButtonTextBesideIcon : Qt::ToolButtonIconOnly;
	opt->subControls = QStyle::SC_ToolButton;
}
Example #6
0
void SystrayHelper::setIconColor(double percentRegular, double percentExtra)
{
    QPixmap iconPixmap(":/trayicon.png");
    QPainter *paint = new QPainter(&iconPixmap);
    paint->setBrush(*(new QColor(255,255,255,255)));
    //paint->drawRect(0,450,591,100);
    //paint->setBrush(*(new QColor(0,0,0,0)));
    paint->drawRect(0,400,20,120);
    paint->setBrush(*(new QColor(255,255,255,255)));
    paint->drawRect(480,400,500,120);

    if(percentExtra > 0){
        paint->setBrush(*(new QColor(255,0,0,255)));
        paint->drawRect(20,450,460*percentExtra,100);
    }else{
        paint->setBrush(*(new QColor(0,200,127,255)));
        paint->drawRect(20,450,460*percentRegular,100);
    }

    delete paint;

    QIcon icon(iconPixmap);

    icon.setIsMask(true);
    m_trayicon->setIcon(icon);
}
int QMessageBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: buttonClicked((*reinterpret_cast< QAbstractButton*(*)>(_a[1]))); break;
        case 1: d_func()->_q_buttonClicked((*reinterpret_cast< QAbstractButton*(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = text(); break;
        case 1: *reinterpret_cast< Icon*>(_v) = icon(); break;
        case 2: *reinterpret_cast< QPixmap*>(_v) = iconPixmap(); break;
        case 3: *reinterpret_cast< Qt::TextFormat*>(_v) = textFormat(); break;
        case 4: *reinterpret_cast<int*>(_v) = QFlag(standardButtons()); break;
        case 5: *reinterpret_cast< QString*>(_v) = detailedText(); break;
        case 6: *reinterpret_cast< QString*>(_v) = informativeText(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setText(*reinterpret_cast< QString*>(_v)); break;
        case 1: setIcon(*reinterpret_cast< Icon*>(_v)); break;
        case 2: setIconPixmap(*reinterpret_cast< QPixmap*>(_v)); break;
        case 3: setTextFormat(*reinterpret_cast< Qt::TextFormat*>(_v)); break;
        case 4: setStandardButtons(QFlag(*reinterpret_cast<int*>(_v))); break;
        case 5: setDetailedText(*reinterpret_cast< QString*>(_v)); break;
        case 6: setInformativeText(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Example #8
0
void MobileAppWizardSymbianOptionsPage::setSvgIcon(const QString &icon)
{
    QPixmap iconPixmap(icon);
    if (!iconPixmap.isNull()) {
        const int symbianIconSize = 44;
        if (iconPixmap.height() > symbianIconSize || iconPixmap.width() > symbianIconSize)
            iconPixmap = iconPixmap.scaledToHeight(symbianIconSize, Qt::SmoothTransformation);
        m_d->ui.appIconPreview->setPixmap(iconPixmap);
        m_d->svgIcon = icon;
    }
}
QIcon patternDockWidget::createIcon(QRgb color,
                                    const QPixmap& symbol) const {

  QPixmap listImage(listIconSize());
  listImage.fill(color);
  QPainter painter(&listImage);
  painter.drawPixmap(0, 0, symbol);
  QPixmap iconPixmap(listIconSize() + QSize(0, 4));
  iconPixmap.fill(Qt::white);
  QPainter painter2(&iconPixmap);
  painter2.drawPixmap(0, 2, listImage);
  return QIcon(iconPixmap);
}
Example #10
0
void KMultiTabBarTab::computeMargins(int* hMargin, int* vMargin) const
{
	// Unfortunately, QStyle does not give us enough information to figure out
	// where to place things, so we try to reverse-engineer it
	QStyleOptionToolButton opt;
	initStyleOption(&opt);

	QPixmap iconPix = iconPixmap();
	QSize trialSize = iconPix.size();
	QSize expandSize = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, trialSize, this);

	*hMargin = (expandSize.width()  - trialSize.width())/2;
	*vMargin = (expandSize.height() - trialSize.height())/2;
}
QThemedImageButton::QThemedImageButton(const QString& iconPath, QWidget *parent)
    : QPushButton(parent), resizeImageValue(false)
{
    if (QFile::exists(iconPath)) {
        QPixmap iconPixmap(iconPath);
        auto iconMask = iconPixmap.createMaskFromColor(Qt::transparent, Qt::MaskInColor);

        QPixmap newPixmap(iconPixmap.size());
        newPixmap.fill(this->palette().foreground().color());
        newPixmap.setMask(iconMask);

        this->setIcon(newPixmap);
    }

    else {
        qDebug() << "QThemedImageButton(Could not load icon: " << iconPath << ")";
    }
}
//! [2]
void MyWidget::mousePressEvent(QMouseEvent *event)
{
//! [2]
    QString text = dataLabel->text();
    QPixmap iconPixmap(32, 32);
    iconPixmap.fill(qRgba(255, 0, 0, 127));
    QImage image(100, 100, QImage::Format_RGB32);
    image.fill(qRgb(0, 0, 255));

//! [3]
    if (event->button() == Qt::LeftButton) {

        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;

        mimeData->setText(text);
        mimeData->setImageData(image);
        drag->setMimeData(mimeData);
        drag->setPixmap(iconPixmap);

        Qt::DropAction dropAction = drag->exec();
//! [3]
        // ...
//! [4]
        event->accept();
    }
//! [4]
    else if (event->button() == Qt::MidButton) {

        QDrag *drag = new QDrag(this);
        QMimeData *mimeData = new QMimeData;

        mimeData->setImageData(image);
        drag->setMimeData(mimeData);
        drag->setPixmap(iconPixmap);

        Qt::DropAction dropAction = drag->exec();
        // ...
        event->accept();
    }
//! [5]
}
Example #13
0
void MobileAppWizardMaemoOptionsPage::setPngIcon(const QString &icon)
{
    QString error;
    QPixmap iconPixmap(icon);
    if (iconPixmap.isNull()) {
        QMessageBox::critical(this, tr("Invalid Icon"),
            tr("The file is not a valid image."));
        return;
    }

    QString actualIconPath;
    if (iconPixmap.size() == m_d->iconSize) {
        actualIconPath = icon;
    } else {
        const QMessageBox::StandardButton button = QMessageBox::warning(this,
            tr("Wrong Icon Size"), tr("The icon needs to be %1x%2 pixels big, "
                "but is not. Do you want Creator to scale it?")
                .arg(m_d->iconSize.width()).arg(m_d->iconSize.height()),
            QMessageBox::Ok | QMessageBox::Cancel);
        if (button != QMessageBox::Ok)
            return;
        iconPixmap = iconPixmap.scaled(m_d->iconSize);
        Utils::TempFileSaver saver;
        saver.setAutoRemove(false);
        if (!saver.hasError())
            saver.setResult(iconPixmap.save(
                    saver.file(), QFileInfo(icon).suffix().toAscii().constData()));
        if (!saver.finalize()) {
            QMessageBox::critical(this, tr("File Error"),
                tr("Could not copy icon file: %1").arg(saver.errorString()));
            return;
        }
        actualIconPath = saver.fileName();
    }

    m_d->ui.pngIconButton->setIcon(iconPixmap);
    m_d->pngIcon = actualIconPath;
}
Example #14
0
EditPlacemarkDialog::EditPlacemarkDialog( GeoDataPlacemark *placemark,
                                          const QHash<qint64, OsmPlacemarkData> *relations,
                                          QWidget *parent ) :
    QDialog( parent ),
    d( new Private( placemark ) )
{
    d->setupUi( this );

    // Store initial style so that it can be restored if the 'Cancel' button is pressed.
    d->m_initialStyle = *placemark->style();

    d->m_initialVisualCategory = placemark->visualCategory();


    d->m_hadInitialOsmData = placemark->hasOsmData();
    if ( d->m_hadInitialOsmData ) {
        d->m_initialOsmData = placemark->osmData();
    }


    // If the placemark has just been created, assign    it a default name.
    if ( placemark->name().isNull() ) {
        placemark->setName( tr("Untitled Placemark") );
    }
    // Setup id, name, icon link and latitude/longitude values.
    d->m_header->setId( placemark->id() );
    d->m_initialId = placemark->id();
    d->m_header->setName( placemark->name() );
    d->m_initialName = placemark->name();
    d->m_isPlacemarkVisible->setChecked( placemark->isVisible() );
    d->m_initialIsPlacemarkVisible = placemark->isVisible();
    d->m_header->setIconLink( placemark->style()->iconStyle().iconPath() );
    d->m_header->setTargetId( placemark->targetId() );
    d->m_initialTargetId = placemark->targetId();
    MarbleWidget* marbleWidget = dynamic_cast<MarbleWidget*>( parent );
    if( marbleWidget != 0 ) {
        const AngleUnit defaultAngleUnit = marbleWidget->defaultAngleUnit();
        const GeoDataCoordinates::Notation notation =
            (defaultAngleUnit == DecimalDegree) ? GeoDataCoordinates::Decimal :
            (defaultAngleUnit == DMSDegree) ?     GeoDataCoordinates::DMS :
            /* else, UTM */                       GeoDataCoordinates::DMS;
        d->m_header->setNotation( notation );
    }
    connect( d->m_header, SIGNAL(valueChanged()), this, SLOT(
                 updateTextAnnotation()) );

    d->m_formattedTextWidget->setText( placemark->description() );
    d->m_initialDescription = placemark->description();
    d->m_initialDescriptionIsCDATA = placemark->descriptionIsCDATA();
    d->m_isBalloonVisible->setChecked( placemark->isBalloonVisible() );
    d->m_initialIsBaloonVisible = placemark->isBalloonVisible();

    d->m_header->setLatitude( placemark->coordinate().latitude( GeoDataCoordinates::Degree ) );
    d->m_header->setLongitude( placemark->coordinate().longitude( GeoDataCoordinates::Degree ) );
    d->m_initialCoords = GeoDataCoordinates( d->m_header->longitude(),
                                             d->m_header->latitude(),
                                             0,
                                             GeoDataCoordinates::Degree );

    // There's no point showing Relations and Tags tabs if the editor was not
    // loaded from the annotate plugin ( loaded from tourWidget.. )
    if ( relations ) {
        // Adding the osm tag editor widget tab
        d->m_osmTagEditorWidget = new OsmTagEditorWidget( placemark, this );
        d->tabWidget->addTab( d->m_osmTagEditorWidget, tr( "Tags" ) );
        QObject::connect( d->m_osmTagEditorWidget, SIGNAL( placemarkChanged( GeoDataFeature* ) ),
                          this, SLOT( updateTextAnnotation() ) );

        // Adding the osm relation editor widget tab
        d->m_osmRelationManagerWidget = new OsmRelationManagerWidget( placemark, relations, this );
        d->tabWidget->addTab( d->m_osmRelationManagerWidget, tr( "Relations" ) );
        QObject::connect( d->m_osmRelationManagerWidget, SIGNAL( relationCreated( const OsmPlacemarkData& ) ),
                          this, SIGNAL( relationCreated( const OsmPlacemarkData& ) ) );
    }

    // Adding the elevation widget tab
    d->m_elevationWidget = new Ui::ElevationWidget;
    QWidget *elevationTab = new QWidget;
    d->m_elevationWidget->setupUi( elevationTab );
    d->tabWidget->addTab( elevationTab, tr("Elevation") );
    qreal altitude = d->m_placemark->coordinate().altitude();
    MarbleLocale *locale = MarbleGlobal::getInstance()->locale();
    if ( altitude == 0.0 ) {
        switch ( locale->measurementSystem() ) {
        case MarbleLocale::MetricSystem:
            d->m_elevationUnit = MarbleLocale::Meter;
            break;
        case MarbleLocale::ImperialSystem:
            d->m_elevationUnit = MarbleLocale::Foot;
            break;
        case MarbleLocale::NauticalSystem:
            d->m_elevationUnit = MarbleLocale::NauticalMile;
            break;
        }

        d->m_elevationWidget->elevationSpinBox->setSuffix( locale->unitAbbreviation((d->m_elevationUnit)) );
    } else {
        qreal convertedAltitude;
        const MarbleLocale::MeasurementSystem currentSystem = locale->measurementSystem();
        locale->meterToTargetUnit( altitude, currentSystem, convertedAltitude, d->m_elevationUnit );
        d->m_elevationWidget->elevationSpinBox->setValue( convertedAltitude );
        d->m_elevationWidget->elevationSpinBox->setSuffix( locale->unitAbbreviation(d->m_elevationUnit) );
    }

    // Adjust icon and label scales.
    d->m_iconScale->setValue( placemark->style()->iconStyle().scale() );
    connect( d->m_iconScale, SIGNAL(valueChanged(double)), this, SLOT(updateTextAnnotation()) );

    d->m_labelScale->setValue( placemark->style()->labelStyle().scale() );
    connect( d->m_labelScale, SIGNAL(valueChanged(double)), this, SLOT(updateTextAnnotation()) );


    // Adjust the current color of the two push buttons' pixmap to resemble the label and icon colors.
    const GeoDataLabelStyle labelStyle = placemark->style()->labelStyle();
    const GeoDataIconStyle iconStyle = placemark->style()->iconStyle();

    QPixmap labelPixmap( d->m_labelButton->iconSize().width(),
                         d->m_labelButton->iconSize().height() );
    labelPixmap.fill( labelStyle.color() );
    d->m_labelButton->setIcon( QIcon( labelPixmap ) );

    QPixmap iconPixmap( d->m_iconButton->iconSize().width(),
                        d->m_iconButton->iconSize().height() );
    iconPixmap.fill( iconStyle.color() );
    d->m_iconButton->setIcon( QIcon( iconPixmap ) );

    // Setup the color dialogs.
    d->m_labelColorDialog = new QColorDialog( this );
    d->m_labelColorDialog->setOption( QColorDialog::ShowAlphaChannel );
    d->m_labelColorDialog->setCurrentColor( labelStyle.color() );
    connect( d->m_labelButton, SIGNAL(clicked()), d->m_labelColorDialog, SLOT(exec()) );
    connect( d->m_labelColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateLabelDialog(QColor)) );
    connect( d->m_labelColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateTextAnnotation()) );

    d->m_iconColorDialog = new QColorDialog( this );
    d->m_iconColorDialog->setOption( QColorDialog::ShowAlphaChannel );
    d->m_iconColorDialog->setCurrentColor( iconStyle.color() );
    connect( d->m_iconButton, SIGNAL(clicked()), d->m_iconColorDialog, SLOT(exec()) );
    connect( d->m_iconColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateIconDialog(QColor)) );
    connect( d->m_iconColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateTextAnnotation()) );

    connect( d->m_isBalloonVisible, SIGNAL(toggled(bool)), this, SLOT(updateTextAnnotation()) );

    // Promote "Ok" button to default button.
    d->buttonBox->button( QDialogButtonBox::Ok )->setDefault( true );

    connect( d->buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(pressed()), this, SLOT(checkFields()) );
    connect( this, SIGNAL(accepted()), SLOT(updateTextAnnotation()) );
    connect( this, SIGNAL(accepted()), SLOT(updatePlacemarkAltitude()) );
    connect( this, SIGNAL(finished(int)), SLOT(restoreInitial(int)) );

    // Ensure that the dialog gets deleted when closing it (either when clicking OK or
    // Close).
    connect( this, SIGNAL(finished(int)), SLOT(deleteLater()) );
}
Example #15
0
void KMultiTabBarTab::paintEvent(QPaintEvent*) {
	QPainter painter(this);

	QStyleOptionToolButton opt;
	initStyleOption(&opt);

	// Paint bevel..
	if (underMouse() || isChecked()) {
		opt.text.clear();
		opt.icon = QIcon();
		style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &painter, this);
	}

	int hMargin, vMargin;
	computeMargins(&hMargin, &vMargin);

	// We first figure out how much room we have for the text, based on
	// icon size and margin, try to fit in by eliding, and perhaps
	// give up on drawing the text entirely if we're too short on room
	QPixmap icon = iconPixmap();
	int textRoom = 0;
	int iconRoom = 0;

	QString t;
	if (shouldDrawText()) {
		if (isVertical()) {
			iconRoom = icon.height() + 2*vMargin;
			textRoom = height() - iconRoom - vMargin;
		} else {
			iconRoom = icon.width() + 2*hMargin;
			textRoom = width() - iconRoom - hMargin;
		}

		t = painter.fontMetrics().elidedText(text(), Qt::ElideRight, textRoom);

		// See whether anything is left. Qt will return either
		// ... or the ellipsis unicode character, 0x2026
		if (t == QLatin1String("...") || t == QChar(0x2026))
			t.clear();
	}

	// Label time.... Simple case: no text, so just plop down the icon right in the center
	// We only do this when the button never draws the text, to avoid jumps in icon position
	// when resizing
 	if (!shouldDrawText()) {
 		style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter | Qt::AlignVCenter, icon);
 		return;
 	}

	// Now where the icon/text goes depends on text direction and tab position
	QRect iconArea;
	QRect labelArea;

	bool bottomIcon = false;
	bool rtl = layoutDirection() == Qt::RightToLeft;
	if (isVertical()) {
		if (m_position == KMultiTabBar::Left && !rtl)
			bottomIcon = true;
		if (m_position == KMultiTabBar::Right && rtl)
			bottomIcon = true;
	}
	//alignFlags = Qt::AlignLeading | Qt::AlignVCenter;

	if (isVertical()) {
		if (bottomIcon) {
			labelArea = QRect(0, vMargin, width(), textRoom);
			iconArea  = QRect(0, vMargin + textRoom, width(), iconRoom);
		} else {
			labelArea = QRect(0, iconRoom, width(), textRoom);
			iconArea  = QRect(0, 0, width(), iconRoom);
		}
	} else {
		// Pretty simple --- depends only on RTL/LTR
		if (rtl) {
			labelArea = QRect(hMargin, 0, textRoom, height());
			iconArea  = QRect(hMargin + textRoom, 0, iconRoom, height());
		} else {
			labelArea = QRect(iconRoom, 0, textRoom, height());
			iconArea  = QRect(0, 0, iconRoom, height());
		}
	}

	style()->drawItemPixmap(&painter, iconArea, Qt::AlignCenter | Qt::AlignVCenter, icon);

	if (t.isEmpty())
		return;

	QRect labelPaintArea = labelArea;

	if (isVertical()) {
		// If we're vertical, we paint to a simple 0,0 origin rect,
		// and get the transformations to get us in the right place
		labelPaintArea = QRect(0, 0, labelArea.height(), labelArea.width());

		QTransform tr;

		if (bottomIcon) {
			tr.translate(labelArea.x(), labelPaintArea.width() + labelArea.y());
			tr.rotate(-90);
		} else {
			tr.translate(labelPaintArea.height() + labelArea.x(), labelArea.y());
			tr.rotate(90);
		}
		painter.setTransform(tr);
	}

	style()->drawItemText(&painter, labelPaintArea, Qt::AlignLeading | Qt::AlignVCenter,
	                      palette(), true, t, QPalette::ButtonText);
}
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;
}
Example #17
0
QFrame *AbstractController::telexFrame()
{
    /**
     * Telextext QFrame
     **/
    QFrame *telexFrame = new QFrame( this );
    QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
    telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
    CONNECT( THEMIM->getIM(), teletextPossible( bool ),
             telexFrame, setVisible( bool ) );

    /* On/Off button */
    QToolButton *telexOn = new QToolButton;
    setupButton( telexOn );
    BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
    telexOn->setEnabled( false );
    telexOn->setCheckable( true );

    telexLayout->addWidget( telexOn );

    /* Teletext Activation and set */
    CONNECT( telexOn, clicked( bool ),
             THEMIM->getIM(), activateTeletext( bool ) );
    CONNECT( THEMIM->getIM(), teletextPossible( bool ),
             telexOn, setEnabled( bool ) );

    /* Transparency button */
    QToolButton *telexTransparent = new QToolButton;
    setupButton( telexTransparent );
    BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
                     qtr( "Toggle Transparency " ) );
    telexTransparent->setEnabled( false );
    telexTransparent->setCheckable( true );
    telexLayout->addWidget( telexTransparent );

    /* Transparency change and set */
    CONNECT( telexTransparent, clicked( bool ),
            THEMIM->getIM(), telexSetTransparency( bool ) );
    CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
             telexTransparent, setChecked( bool ) );


    /* Page setting */
    QSpinBox *telexPage = new QSpinBox( telexFrame );
    telexPage->setRange( 100, 899 );
    telexPage->setValue( 100 );
    telexPage->setAccelerated( true );
    telexPage->setWrapping( true );
    telexPage->setAlignment( Qt::AlignRight );
    telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
    telexPage->setEnabled( false );
    telexLayout->addWidget( telexPage );

    /* Contextual & Index Buttons */
    QSignalMapper *contextButtonMapper = new QSignalMapper( this );
    QToolButton *contextButton = NULL;
    int i_iconminsize = __MAX( 16, telexOn->minimumHeight() );
    QPixmap iconPixmap( i_iconminsize, i_iconminsize );
    iconPixmap.fill( Qt::transparent );
    QPainter iconPixmapPainter( &iconPixmap );
    QLinearGradient iconPixmapPainterGradient( iconPixmap.rect().center() / 2,
                                               iconPixmap.rect().center() );

#define CREATE_CONTEXT_BUTTON(color, key) \
    iconPixmapPainterGradient.setColorAt( 0, QColor( color ).lighter(150) );\
    iconPixmapPainterGradient.setColorAt( 1.0, QColor( color ) );\
    iconPixmapPainter.setBrush( iconPixmapPainterGradient );\
    iconPixmapPainter.drawEllipse( iconPixmap.rect().adjusted( 4, 4, -5, -5 ) );\
    contextButton = new QToolButton();\
    setupButton( contextButton );\
    contextButton->setIcon( iconPixmap );\
    contextButton->setEnabled( false );\
    contextButtonMapper->setMapping( contextButton, key << 16 );\
    CONNECT( contextButton, clicked(), contextButtonMapper, map() );\
    CONNECT( contextButtonMapper, mapped( int ),\
             THEMIM->getIM(), telexSetPage( int ) );\
    CONNECT( THEMIM->getIM(), teletextActivated( bool ), contextButton, setEnabled( bool ) );\
    telexLayout->addWidget( contextButton )

    CREATE_CONTEXT_BUTTON("grey", 'i'); /* index */
    CREATE_CONTEXT_BUTTON("red", 'r');
    CREATE_CONTEXT_BUTTON("green", 'g');
    CREATE_CONTEXT_BUTTON("yellow", 'y');
    CREATE_CONTEXT_BUTTON("blue", 'b');

#undef CREATE_CONTEXT_BUTTON

    /* Page change and set */
    CONNECT( telexPage, valueChanged( int ),
            THEMIM->getIM(), telexSetPage( int ) );
    CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
            telexPage, setValue( int ) );

    CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
    CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
    CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
    return telexFrame;
}