Пример #1
0
void IconDialog::setIconSize(int iconSize)
{
    if (m_dialog->iconSize() != iconSize) {
        m_iconSize = iconSize;
        emit iconSizeChanged(iconSize);
    }
}
void QToolBar::setIconSize(const QSize &iconSize)
{
    Q_D(QToolBar);
    QSize sz = iconSize;
    if (!sz.isValid()) {
        QMainWindow *mw = qobject_cast<QMainWindow *>(parentWidget());
        if (mw && mw->layout()) {
            QLayout *layout = mw->layout();
            int i = 0;
            QLayoutItem *item = 0;
            do {
                item = layout->itemAt(i++);
                if (item && (item->widget() == this))
                    sz = mw->iconSize();
            } while (!sz.isValid() && item != 0);
        }
    }
    if (!sz.isValid()) {
        const int metric = style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, this);
        sz = QSize(metric, metric);
    }
    if (d->iconSize != sz) {
        d->iconSize = sz;
        setMinimumSize(0, 0);
        emit iconSizeChanged(d->iconSize);
    }
    d->explicitIconSize = iconSize.isValid();

    d->layout->invalidate();
}
Пример #3
0
void KToolBar::Private::init(bool readConfig, bool _isMainToolBar)
{
  isMainToolBar = _isMainToolBar;
  loadKDESettings();

  // also read in our configurable settings (for non-xmlgui toolbars)
  // KDE5: we can probably remove this, if people save settings then they load them too, e.g. using KMainWindow's autosave.
  if (readConfig) {
      KConfigGroup cg(KGlobal::config(), QString());
      q->applySettings(cg);
  }

  if (q->mainWindow()) {
    // Get notified when settings change
    connect(q, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas)),
             q->mainWindow(), SLOT(setSettingsDirty()));
    connect(q, SIGNAL(iconSizeChanged(QSize)),
             q->mainWindow(), SLOT(setSettingsDirty()));
    connect(q, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
             q->mainWindow(), SLOT(setSettingsDirty()));
    connect(q, SIGNAL(movableChanged(bool)),
             q->mainWindow(), SLOT(setSettingsDirty()));
    connect(q, SIGNAL(orientationChanged(Qt::Orientation)),
             q->mainWindow(), SLOT(setSettingsDirty()));
  }
Пример #4
0
void KoColorPopupButton::resizeEvent(QResizeEvent *e)
{
    QStyleOptionToolButton opt;
    initStyleOption(&opt);
    QSize size = iconSize();

    QSize rect = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, size, this);
    int iconWidth = size.width() - rect.width() + e->size().width();

    if (iconWidth != size.width()) {
        size.setWidth(iconWidth);
        setIconSize(size);
    }
    QToolButton::resizeEvent(e);

    emit iconSizeChanged();
}
Пример #5
0
ToolButtonWidget::ToolButtonWidget(QWidget *parent) : QToolButton(parent)
{
	setAutoRaise(true);
	setContextMenuPolicy(Qt::NoContextMenu);

	ToolBarWidget *toolBar = qobject_cast<ToolBarWidget*>(parent);

	if (toolBar)
	{
		setIconSize(toolBar->iconSize());
		setMaximumButtonSize(toolBar->getMaximumButtonSize());
		setToolButtonStyle(toolBar->toolButtonStyle());

		connect(toolBar, SIGNAL(iconSizeChanged(QSize)), this, SLOT(setIconSize(QSize)));
		connect(toolBar, SIGNAL(maximumButtonSizeChanged(int)), this, SLOT(setMaximumButtonSize(int)));
		connect(toolBar, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), this, SLOT(setToolButtonStyle(Qt::ToolButtonStyle)));
	}
}
Пример #6
0
void KToolBar::Private::init(bool readConfig, bool _isMainToolBar)
{
    isMainToolBar = _isMainToolBar;
    loadKDESettings();

    // also read in our configurable settings (for non-xmlgui toolbars)
    if (readConfig) {
        KConfigGroup cg(KSharedConfig::openConfig(), QString());
        q->applySettings(cg);
    }

    if (q->mainWindow()) {
        // Get notified when settings change
        connect(q, SIGNAL(allowedAreasChanged(Qt::ToolBarAreas)),
                q->mainWindow(), SLOT(setSettingsDirty()));
        connect(q, SIGNAL(iconSizeChanged(QSize)),
                q->mainWindow(), SLOT(setSettingsDirty()));
        connect(q, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),
                q->mainWindow(), SLOT(setSettingsDirty()));
        connect(q, SIGNAL(movableChanged(bool)),
                q->mainWindow(), SLOT(setSettingsDirty()));
        connect(q, SIGNAL(orientationChanged(Qt::Orientation)),
                q->mainWindow(), SLOT(setSettingsDirty()));
    }
void tst_QToolBar::iconSize()
{
    {
        QToolBar tb;

        QSignalSpy spy(&tb, SIGNAL(iconSizeChanged(QSize)));

        // the default is determined by the style
        const int metric = tb.style()->pixelMetric(QStyle::PM_ToolBarIconSize);
        const QSize defaultIconSize = QSize(metric, metric);
        const QSize smallIconSize = QSize(metric / 2, metric / 2);
        const QSize largeIconSize = QSize(metric * 2, metric * 2);

        QCOMPARE(tb.iconSize(), defaultIconSize);
        tb.setIconSize(defaultIconSize);
        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(spy.count(), 0);

        spy.clear();
        tb.setIconSize(largeIconSize);
        QCOMPARE(tb.iconSize(), largeIconSize);
        QCOMPARE(spy.count(), 1);
        QCOMPARE(spy.first().first().toSize(), largeIconSize);

        // no-op
        spy.clear();
        tb.setIconSize(largeIconSize);
        QCOMPARE(tb.iconSize(), largeIconSize);
        QCOMPARE(spy.count(), 0);

        spy.clear();
        tb.setIconSize(defaultIconSize);
        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(spy.count(), 1);
        QCOMPARE(spy.first().first().toSize(), defaultIconSize);

        // no-op
        spy.clear();
        tb.setIconSize(defaultIconSize);
        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(spy.count(), 0);

        spy.clear();
        tb.setIconSize(smallIconSize);
        QCOMPARE(tb.iconSize(), smallIconSize);
        QCOMPARE(spy.count(), 1);
        QCOMPARE(spy.first().first().toSize(), smallIconSize);

        // no-op
        spy.clear();
        tb.setIconSize(smallIconSize);
        QCOMPARE(tb.iconSize(), smallIconSize);
        QCOMPARE(spy.count(), 0);

        // setting the icon size to an invalid QSize will reset the
        // iconSize property to the default
        tb.setIconSize(QSize());
        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(spy.size(), 1);
        QCOMPARE(spy.first().first().toSize(), defaultIconSize);
        spy.clear();
    }

    {
        QMainWindow mw;
        QToolBar tb;
        QSignalSpy mwSpy(&mw, SIGNAL(iconSizeChanged(QSize)));
        QSignalSpy tbSpy(&tb, SIGNAL(iconSizeChanged(QSize)));

        // the default is determined by the style
        const int metric = tb.style()->pixelMetric(QStyle::PM_ToolBarIconSize);
        const QSize defaultIconSize = QSize(metric, metric);
        const QSize smallIconSize = QSize(metric / 2, metric / 2);
        const QSize largeIconSize = QSize(metric * 2, metric * 2);

        mw.setIconSize(smallIconSize);

        // explicitly set it to the default
        tb.setIconSize(defaultIconSize);
        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(tbSpy.count(), 0);

        mw.addToolBar(&tb);

        // tb icon size should not change since it has been explicitly set
        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(tbSpy.count(), 0);

        mw.setIconSize(largeIconSize);

        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(tbSpy.count(), 0);

        mw.setIconSize(defaultIconSize);

        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(tbSpy.count(), 0);

        mw.setIconSize(smallIconSize);

        QCOMPARE(tb.iconSize(), defaultIconSize);
        QCOMPARE(tbSpy.count(), 0);

        // resetting to the default should cause the toolbar to take
        // on the mainwindow's icon size
        tb.setIconSize(QSize());
        QCOMPARE(tb.iconSize(), smallIconSize);
        QCOMPARE(tbSpy.size(), 1);
        QCOMPARE(tbSpy.first().first().toSize(), smallIconSize);
        tbSpy.clear();
    }
}
Пример #8
0
int QToolBar::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: actionTriggered((*reinterpret_cast< QAction*(*)>(_a[1]))); break;
        case 1: movableChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 2: allowedAreasChanged((*reinterpret_cast< Qt::ToolBarAreas(*)>(_a[1]))); break;
        case 3: orientationChanged((*reinterpret_cast< Qt::Orientation(*)>(_a[1]))); break;
        case 4: iconSizeChanged((*reinterpret_cast< const QSize(*)>(_a[1]))); break;
        case 5: toolButtonStyleChanged((*reinterpret_cast< Qt::ToolButtonStyle(*)>(_a[1]))); break;
        case 6: topLevelChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 7: setIconSize((*reinterpret_cast< const QSize(*)>(_a[1]))); break;
        case 8: setToolButtonStyle((*reinterpret_cast< Qt::ToolButtonStyle(*)>(_a[1]))); break;
        case 9: d_func()->_q_toggleView((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 10: d_func()->_q_updateIconSize((*reinterpret_cast< const QSize(*)>(_a[1]))); break;
        case 11: d_func()->_q_updateToolButtonStyle((*reinterpret_cast< Qt::ToolButtonStyle(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 12;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< bool*>(_v) = isMovable(); break;
        case 1: *reinterpret_cast< Qt::ToolBarAreas*>(_v) = allowedAreas(); break;
        case 2: *reinterpret_cast< Qt::Orientation*>(_v) = orientation(); break;
        case 3: *reinterpret_cast< QSize*>(_v) = iconSize(); break;
        case 4: *reinterpret_cast< Qt::ToolButtonStyle*>(_v) = toolButtonStyle(); break;
        case 5: *reinterpret_cast< bool*>(_v) = isFloating(); break;
        case 6: *reinterpret_cast< bool*>(_v) = isFloatable(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setMovable(*reinterpret_cast< bool*>(_v)); break;
        case 1: setAllowedAreas(*reinterpret_cast< Qt::ToolBarAreas*>(_v)); break;
        case 2: setOrientation(*reinterpret_cast< Qt::Orientation*>(_v)); break;
        case 3: setIconSize(*reinterpret_cast< QSize*>(_v)); break;
        case 4: setToolButtonStyle(*reinterpret_cast< Qt::ToolButtonStyle*>(_v)); break;
        case 6: setFloatable(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        bool *_b = reinterpret_cast<bool*>(_a[0]);
        switch (_id) {
        case 0: *_b = (qobject_cast<QMainWindow*>(parentWidget())!=0); break;
        case 1: *_b = (qobject_cast<QMainWindow*>(parentWidget())!=0); break;
        case 2: *_b = (qobject_cast<QMainWindow*>(parentWidget())==0); break;
        }
        _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;
}
Пример #9
0
MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow),
	settings(new QSettings(this)),
	mainModel(new PixmapModel(this)),
	previewDock(new IconViewDockWidget(this)),
	updateController(new QtAutoUpdater::UpdateController(this))//TODO "this" not ok because of conflict with sheets on mac ?!?
{
	this->initSettings();

	//setup basic ui
	this->ui->setupUi(this);
	this->addDockWidget(Qt::RightDockWidgetArea, this->previewDock);
	this->previewDock->hide();
	this->ui->basePathEdit->setDefaultDirectory(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
	this->ui->versionLabel->setText(QCoreApplication::applicationVersion());
	this->ui->tabWidget->setCurrentIndex(0);
	this->ui->loadViewListView->setModel(this->mainModel);
	this->ui->updatesLayout->replaceWidget(this->ui->checkUpdatesPlaceholder,
										   this->updateController->createUpdatePanel(this));
	this->ui->checkUpdatesPlaceholder->deleteLater();

#ifdef Q_OS_OSX
	//Mac actions...
	QMenu *menu = this->menuBar()->addMenu(tr("Help"));
	menu->addAction(this->updateController->getUpdateAction());
	QAction *aboutAction = new QAction(this->ui->aboutButton->text(), this);
	aboutAction->setMenuRole(QAction::AboutQtRole);
	connect(aboutAction, &QAction::triggered, qApp, &QApplication::aboutQt);
	menu->addAction(aboutAction);
#endif

	//setup actions
	this->ui->loadViewListView->addActions({
											   this->ui->actionAdd_File,
											   this->ui->actionRemove,
											   this->ui->actionClear_All
										   });
	this->ui->addIconButton->setDefaultAction(this->ui->actionAdd_File);
	this->ui->removeIconButton->addActions({
											   this->ui->actionRemove,
											   this->ui->actionClear_All
										   });
	this->ui->removeIconButton->setDefaultAction(this->ui->actionRemove);

	//setup icon sizes
	connect(this, &MainWindow::iconSizeChanged,
			this->ui->addIconButton, &QToolButton::setIconSize);
	connect(this, &MainWindow::iconSizeChanged,
			this->ui->removeIconButton, &QToolButton::setIconSize);
	this->setIconSize(QSize(24, 24) * (QApplication::primaryScreen()->logicalDotsPerInch() / 96.));//TODO experimental high dpi support?
	emit iconSizeChanged(this->iconSize());

	//restore gui
	this->settings->beginGroup(QStringLiteral("gui"));
	this->restoreGeometry(this->settings->value(QStringLiteral("geom")).toByteArray());
	this->restoreState(this->settings->value(QStringLiteral("state")).toByteArray());
	this->restoreDockWidget(this->previewDock);
	this->settings->endGroup();

	//restore dpi-states and ohter settings values
	this->settings->beginGroup(QStringLiteral("dpiRates"));
	this->ui->ldpiCheckBox->setChecked(this->settings->value(QStringLiteral("ldpi"), true).toBool());
	this->ui->mdpiCheckBox->setChecked(this->settings->value(QStringLiteral("mdpi"), true).toBool());
	this->ui->hdpiCheckBox->setChecked(this->settings->value(QStringLiteral("hdpi"), true).toBool());
	this->ui->xhdpiCheckBox->setChecked(this->settings->value(QStringLiteral("xhdpi"), true).toBool());
	this->ui->xxhdpiCheckBox->setChecked(this->settings->value(QStringLiteral("xxhdpi"), true).toBool());
	this->ui->xxxhdpiCheckBox->setChecked(this->settings->value(QStringLiteral("xxxhdpi"), true).toBool());
	this->settings->endGroup();
	this->ui->basePathEdit->setPath(this->settings->value(QStringLiteral("paths/savePath")).toString());

	//restore all custom profiles
	this->settings->beginGroup(QStringLiteral("templates"));
	this->ui->iconTypeComboBox->addItems(this->settings->childGroups());
	this->settings->endGroup();
	this->ui->iconTypeComboBox->setCurrentText(this->settings->value(QStringLiteral("recentProfile"), tr("Launcher Icon")).toString());

	//connections
	connect(this->ui->aboutButton, &QPushButton::clicked, qApp, &QApplication::aboutQt);
	connect(this->ui->previewCheckBox, &QCheckBox::clicked, this->previewDock, &IconViewDockWidget::setVisible);
	connect(this->previewDock, &IconViewDockWidget::visibilityChanged, this->ui->previewCheckBox, &QCheckBox::setChecked);
	this->ui->previewCheckBox->setChecked(this->previewDock->isVisible());
	connect(this->mainModel, &PixmapModel::rowsChanged, this, &MainWindow::rowsChanged);
	connect(this->ui->loadViewListView->selectionModel(), &QItemSelectionModel::currentChanged,
			this, &MainWindow::selectionChanged);
	connect(this->ui->actionClear_All, &QAction::triggered, this->mainModel, &PixmapModel::reset);

	//init functions
	this->on_iconTypeComboBox_activated(this->ui->iconTypeComboBox->currentText());
	this->updateController->scheduleUpdate(QDateTime::currentDateTime().addSecs(5));
}
void ColorPaletteModel::setIconSize(const QSize& iconSize)
{
    if ( p->icon_size != iconSize )
        emit iconSizeChanged( p->icon_size = iconSize );
}