void ColorSpinBoxGroup::setColor(const QColor &c)
{
    if(c == color_) return;
    noColorUpdate = true;
    if(isRgbColors){
        ui->RedspinBox->setValue(c.red());
        ui->GreenspinBox->setValue(c.green());
        ui->BluespinBox->setValue(c.blue());
    }else{
        ui->RedspinBox->setValue(
                    qBound(0.0, c.hsvHueF()*359, 359.0)
                    );
        ui->GreenspinBox->setValue(
                    qBound(0.0, c.hsvSaturationF()*100, 100.0)
                    );
        ui->BluespinBox->setValue(
                    qBound(0.0, c.valueF()*100, 100.0)
                    );
    }
    color_ = c;
    QPalette p = ui->label->palette();
    p.setColor(QPalette::Background, color_);
    ui->label->setPalette(p);
    noColorUpdate = false;
}
Example #2
0
float Theme::getHue(QString color) {

    QColor c;
    c.setNamedColor(color);
    QColor converted = c.toHsv();
    return converted.hsvHueF();
}
Example #3
0
void ColorInspector::setColor(const QColor &newColor)
{
    if (newColor == m_color)
    {
        return;
    }
    noColorUpdate = true;

    if(isRgbColors)
    {
        ui->RedspinBox->setValue(newColor.red());
        ui->GreenspinBox->setValue(newColor.green());
        ui->BluespinBox->setValue(newColor.blue());
        ui->AlphaspinBox->setValue(newColor.alpha());
    }
    else
    {
        ui->RedspinBox->setValue( qBound(0.0, newColor.hsvHueF() * 359, 359.0) );
        ui->GreenspinBox->setValue( qBound(0.0, newColor.hsvSaturationF() * 100, 100.0) );
        ui->BluespinBox->setValue( qBound(0.0, newColor.valueF() * 100, 100.0) );
        ui->AlphaspinBox->setValue( qBound(0.0, newColor.alphaF() * 100, 100.0) );
    }
    m_color = newColor;

    QPalette p = ui->color->palette();
    p.setColor(QPalette::Background, m_color);
    ui->color->setPalette(p);
    //ui->color->setFixedSize(30,30);
    noColorUpdate = false;
}
void Color2DSlider::setColor(const QColor& c)
{
    p->hue = c.hsvHueF();
    p->sat = c.saturationF();
    p->val = c.valueF();
    p->renderSquare(size());
    update();
    emit colorChanged(color());
}
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel):
        QWidget(),
    m_declarativeView(new QDeclarativeView(this)),
    m_statesEditorView(statesEditorView),
    m_imageProvider(0)
{
    m_imageProvider = new Internal::StatesEditorImageProvider;
    m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());
    m_declarativeView->engine()->addImageProvider(
            QLatin1String("qmldesigner_stateseditor"), m_imageProvider);

    m_declarativeView->setAcceptDrops(false);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setMargin(0);
    layout->setSpacing(0);
    layout->addWidget(m_declarativeView.data());

    m_declarativeView->setResizeMode(QDeclarativeView::SizeRootObjectToView);

    m_declarativeView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel);
    QColor highlightColor = palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    m_declarativeView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);

    // Work around ASSERT in the internal QGraphicsScene that happens when
    // the scene is created + items set dirty in one event loop run (BAUHAUS-459)
    //QApplication::processEvents();

    m_declarativeView->setSource(QUrl("qrc:/stateseditor/stateslist.qml"));

    if (!m_declarativeView->rootObject())
        throw InvalidQmlSourceException(__LINE__, __FUNCTION__, __FILE__);

    m_declarativeView->setFocusPolicy(Qt::ClickFocus);
    QApplication::sendEvent(m_declarativeView->scene(), new QEvent(QEvent::WindowActivate));

    connect(m_declarativeView->rootObject(), SIGNAL(currentStateInternalIdChanged()), statesEditorView, SLOT(synchonizeCurrentStateFromWidget()));
    connect(m_declarativeView->rootObject(), SIGNAL(createNewState()), statesEditorView, SLOT(createNewState()));
    connect(m_declarativeView->rootObject(), SIGNAL(deleteState(int)), statesEditorView, SLOT(removeState(int)));

    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));

    setWindowTitle(tr("States", "Title of Editor widget"));
}
Example #6
0
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel)
    : QWidget(),
      m_quickView(new QQuickView()),
      m_statesEditorView(statesEditorView),
      m_imageProvider(0),
      m_qmlSourceUpdateShortcut(0)
{
    m_imageProvider = new Internal::StatesEditorImageProvider;
    m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());

    m_quickView->engine()->addImageProvider(QLatin1String("qmldesigner_stateseditor"), m_imageProvider);
    m_quickView->engine()->addImportPath(statesEditorResourcesPath());

    //m_quickView->setAcceptDrops(false);

    m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F4), this);
    connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));

    QVBoxLayout *layout = new QVBoxLayout(this);
    setMinimumHeight(160);
    layout->setMargin(0);
    layout->setSpacing(0);
    QWidget *container = createWindowContainer(m_quickView.data());
    layout->addWidget(container);

    m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);

    m_quickView->rootContext()->setContextProperty(QLatin1String("statesEditorModel"), statesEditorModel);
    QColor highlightColor = palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    m_quickView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);

    m_quickView->rootContext()->setContextProperty("canAddNewStates", true);

    setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));

    setWindowTitle(tr("States", "Title of Editor widget"));

    // init the first load of the QML UI elements
    reloadQmlSource();
}
Example #7
0
void drawSelectionBackground(QPainter *painter, const QStyleOption &option)
{
    QWidget colorReference;

    painter->save();
    QLinearGradient gradient;
    QColor highlightColor = colorReference.palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    gradient.setColorAt(0, highlightColor.lighter(130));
    gradient.setColorAt(1, highlightColor.darker(130));
    gradient.setStart(option.rect.topLeft());
    gradient.setFinalStop(option.rect.bottomLeft());
    painter->fillRect(option.rect, gradient);
    painter->setPen(highlightColor.lighter());
    painter->drawLine(option.rect.topLeft(),option.rect.topRight());
    painter->setPen(highlightColor.darker());
    painter->drawLine(option.rect.bottomLeft(),option.rect.bottomRight());
    painter->restore();
}
Example #8
0
ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
    QFrame(parent),
    m_iconProvider(m_resIconSize),
    m_itemIconSize(24, 24),
    m_resIconSize(24, 24),
    m_itemsView(new QDeclarativeView(this)),
    m_resourcesView(new Internal::ItemLibraryTreeView(this)),
    m_filterFlag(QtBasic)
{
    setWindowTitle(tr("Library", "Title of library view"));

    /* create Items view and its model */
    m_itemsView->setAttribute(Qt::WA_OpaquePaintEvent);
    m_itemsView->setAttribute(Qt::WA_NoSystemBackground);
    m_itemsView->setAcceptDrops(false);
    m_itemsView->setFocusPolicy(Qt::ClickFocus);
    m_itemsView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    m_itemLibraryModel = new Internal::ItemLibraryModel(QDeclarativeEnginePrivate::getScriptEngine(m_itemsView->engine()), this);
    m_itemLibraryModel->setItemIconSize(m_itemIconSize);

    QDeclarativeContext *rootContext = m_itemsView->rootContext();
    rootContext->setContextProperty(QLatin1String("itemLibraryModel"), m_itemLibraryModel.data());
    rootContext->setContextProperty(QLatin1String("itemLibraryIconWidth"), m_itemIconSize.width());
    rootContext->setContextProperty(QLatin1String("itemLibraryIconHeight"), m_itemIconSize.height());

    QColor highlightColor = palette().highlight().color();
    if (0.5*highlightColor.saturationF()+0.75-highlightColor.valueF() < 0)
        highlightColor.setHsvF(highlightColor.hsvHueF(),0.1 + highlightColor.saturationF()*2.0, highlightColor.valueF());
    m_itemsView->rootContext()->setContextProperty(QLatin1String("highlightColor"), highlightColor);

    // loading the qml has to come after all needed context properties are set
    m_itemsView->setSource(QUrl("qrc:/ItemLibrary/qml/ItemsView.qml"));

    QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem*>(m_itemsView->rootObject());
    connect(rootItem, SIGNAL(itemSelected(int)), this, SLOT(showItemInfo(int)));
    connect(rootItem, SIGNAL(itemDragged(int)), this, SLOT(startDragAndDrop(int)));
    connect(this, SIGNAL(scrollItemsView(QVariant)), rootItem, SLOT(scrollView(QVariant)));
    connect(this, SIGNAL(resetItemsView()), rootItem, SLOT(resetView()));

    /* create Resources view and its model */
    m_resourcesFileSystemModel = new QFileSystemModel(this);
    m_resourcesFileSystemModel->setIconProvider(&m_iconProvider);
    m_resourcesView->setModel(m_resourcesFileSystemModel.data());
    m_resourcesView->setIconSize(m_resIconSize);

    /* create image provider for loading item icons */
    m_itemsView->engine()->addImageProvider(QLatin1String("qmldesigner_itemlibrary"), new Internal::ItemLibraryImageProvider);

    /* other widgets */
    QTabBar *tabBar = new QTabBar(this);
    tabBar->addTab(tr("Items", "Title of library items view"));
    tabBar->addTab(tr("Resources", "Title of library resources view"));
    tabBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    m_lineEdit = new Utils::FilterLineEdit(this);
    m_lineEdit->setObjectName(QLatin1String("itemLibrarySearchInput"));
    m_lineEdit->setPlaceholderText(tr("<Filter>", "Library search input hint text"));
    m_lineEdit->setDragEnabled(false);
    m_lineEdit->setMinimumWidth(75);
    m_lineEdit->setTextMargins(0, 0, 20, 0);
    QWidget *lineEditFrame = new QWidget(this);
    lineEditFrame->setObjectName(QLatin1String("itemLibrarySearchInputFrame"));
    QGridLayout *lineEditLayout = new QGridLayout(lineEditFrame);
    lineEditLayout->setMargin(2);
    lineEditLayout->setSpacing(0);
    lineEditLayout->addItem(new QSpacerItem(5, 3, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 0, 1, 3);
    lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 0);
    lineEditLayout->addWidget(m_lineEdit.data(), 1, 1, 1, 1);
    lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 2);
    connect(m_lineEdit.data(), SIGNAL(filterChanged(QString)), this, SLOT(setSearchFilter(QString)));

    m_stackedWidget = new QStackedWidget(this);
    m_stackedWidget->addWidget(m_itemsView.data());
    m_stackedWidget->addWidget(m_resourcesView.data());
    connect(tabBar, SIGNAL(currentChanged(int)),
            m_stackedWidget.data(), SLOT(setCurrentIndex(int)));
    connect(tabBar, SIGNAL(currentChanged(int)),
            this, SLOT(updateSearch()));

    QWidget *spacer = new QWidget(this);
    spacer->setObjectName(QLatin1String("itemLibrarySearchInputSpacer"));
    spacer->setFixedHeight(4);

    QGridLayout *layout = new QGridLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);
    layout->addWidget(tabBar, 0, 0, 1, 1);
    layout->addWidget(spacer, 1, 0);
    layout->addWidget(lineEditFrame, 2, 0, 1, 1);
    layout->addWidget(m_stackedWidget.data(), 3, 0, 1, 1);

    setResourcePath(QDir::currentPath());
    setSearchFilter(QString());

    /* style sheets */
    setStyleSheet(QLatin1String(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css")));
    m_resourcesView->setStyleSheet(
            QLatin1String(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
}