Ejemplo n.º 1
0
			QToolButton* PackagesDelegate::GetUpdate (const QModelIndex& index) const
			{
				int row = index.row ();
				if (!Row2Update_.contains (row))
				{
					QAction *action = new QAction (Core::Instance ()
								.GetProxy ()->GetIcon ("update"),
							tr ("Update"),
							Viewport_);
					action->setCheckable (true);
					action->setProperty ("Role", "Update");
					connect (action,
							SIGNAL (triggered ()),
							this,
							SLOT (handleAction ()));

					QToolButton *toolButton = new QToolButton ();
					toolButton->resize (CActionsSize, CActionsSize);
					toolButton->setDefaultAction (action);
					Row2Update_ [row] = toolButton;
				}

				QToolButton *button = Row2Update_ [row];
				QAction *action = button->defaultAction ();

				bool upgradable = index.data (PackagesModel::PMRUpgradable).toBool ();
				action->setEnabled (upgradable);
				action->setData (index.data (PackagesModel::PMRPackageID));

				WasUpgradable_ [index] = upgradable;

				return button;
			}
Ejemplo n.º 2
0
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentSeveralActions()
{
    KSelectAction selectAction("selectAction", 0);
    selectAction.setToolBarMode(KSelectAction::MenuMode);

    selectAction.addAction(new QAction("action1", &selectAction));
    selectAction.addAction(new QAction("action2", &selectAction));
    selectAction.addAction(new QAction("action3", &selectAction));

    QToolBar toolBar;
    toolBar.addAction(&selectAction);
    QWidget* widget = toolBar.widgetForAction(&selectAction);

    QVERIFY(widget);
    QToolButton* toolButton = qobject_cast<QToolButton*>(widget);
    QVERIFY(toolButton);
    QVERIFY(toolButton->isEnabled());
    QVERIFY(toolButton->autoRaise());
    QCOMPARE((int)toolButton->focusPolicy(), (int)Qt::NoFocus);
    QCOMPARE(toolButton->defaultAction(), (QAction*)&selectAction);
    QCOMPARE(toolButton->actions().count(), 4);
    QCOMPARE(toolButton->actions().at(0)->text(), QString("selectAction"));
    QCOMPARE(toolButton->actions().at(1)->text(), QString("action1"));
    QCOMPARE(toolButton->actions().at(2)->text(), QString("action2"));
    QCOMPARE(toolButton->actions().at(3)->text(), QString("action3"));
}
Ejemplo n.º 3
0
void QCastViewGL::onCameraChangeAction()
{
   QAction *pAct = qobject_cast< QAction* >(QObject::sender());
   if (!pAct) return;
   QVariant v = pAct->data();
   void* pc = v.value<void*>();
   cogx::display::CDisplayCamera* pCamera = static_cast<cogx::display::CDisplayCamera*>(pc);
   //std::cout << pAct << " " << pAct->text().toStdString() << " " << pc << " " << pCamera << std::endl;

   if (pCamera) {
      // TODO: should check if it is valid -- is it in getCameras()?
      selectCamera(pCamera);
   }

   // Replace the action for the button.
   // Parent hierarchy: action -> menu -> button
   QMenu *pMenu = qobject_cast< QMenu* >(pAct->parent());
   if (pMenu) {
      QToolButton* pBut = qobject_cast< QToolButton* >(pMenu->parent());
      if (pBut) {
         QAction *pOldAct = pBut->defaultAction();
         if (pOldAct && pOldAct->parent() == pAct->parent()) {
            //std::cout << "Changing default action" << std::endl;
            pBut->setDefaultAction(pAct);
         }
      }
   }
}
Ejemplo n.º 4
0
QToolButton* ActionListWidget::toolButtonForAction(QAction* action) {
    for (int i=0; i<layout()->count(); i++ ) {
        QWidget* widget = layout()->itemAt(i)->widget();
        if (widget) {
            QToolButton* button = static_cast<QToolButton*>(widget);
            if (button->defaultAction() == action) {
                return button;
            }
        }
    }

    return 0;
}
Ejemplo n.º 5
0
			QToolButton* PackagesDelegate::GetInstallRemove (const QModelIndex& index) const
			{
				int row = index.row ();
				if (!Row2InstallRemove_.contains (row))
				{
					QAction *action = new QAction (Viewport_);
					action->setCheckable (true);
					action->setProperty ("Role", "InstallRemove");
					connect (action,
							SIGNAL (triggered ()),
							this,
							SLOT (handleAction ()));

					QToolButton *toolButton = new QToolButton ();
					toolButton->resize (CActionsSize, CActionsSize);
					toolButton->setDefaultAction (action);
					Row2InstallRemove_ [row] = toolButton;
				}

				QToolButton *button = Row2InstallRemove_ [row];

				bool installed = index.data (PackagesModel::PMRInstalled).toBool ();
				QString label;
				QString iconName;
				if (installed)
				{
					label = tr ("Remove");
					iconName = "remove";
				}
				else
				{
					label = tr ("Install");
					iconName = "addjob";
				}

				QAction *action = button->defaultAction ();
				WasInstalled_ [index] = installed;

				action->setText (label);
				action->setIcon (Core::Instance ().GetProxy ()->GetIcon (iconName));
				action->setData (index.data (PackagesModel::PMRPackageID));
				action->setProperty ("Installed", index.data (PackagesModel::PMRInstalled));

				return button;
			}
Ejemplo n.º 6
0
bool QgsCustomizationDialog::switchWidget( QWidget *widget, QMouseEvent *e )
{
  Q_UNUSED( e );
  QgsDebugMsg( "Entered" );
  if ( !actionCatch->isChecked() )
    return false;
  QString path = widgetPath( widget );
  QgsDebugMsg( "path = " + path );

  if ( path.startsWith( "/QgsCustomizationDialogBase" ) )
  {
    // do not allow modification of this dialog
    return false;
  }
  else if ( path.startsWith( "/QgisApp" ) )
  {
    // changes to main window
    // (work with toolbars, tool buttons)
    if ( widget->inherits( "QToolBar" ) )
    {
      path = "/Toolbars/" + widget->objectName();
    }
    else if ( widget->inherits( "QToolButton" ) )
    {
      QToolButton* toolbutton = qobject_cast<QToolButton*>( widget );
      QAction* action = toolbutton->defaultAction();
      if ( !action )
        return false;
      QString toolbarName = widget->parent()->objectName();
      QString actionName = action->objectName();
      path = "/Toolbars/" + toolbarName + '/' + actionName;
    }
    else
    {
      // unsupported widget in main window
      return false;
    }
  }
  else
  {
    // ordinary widget in a dialog
    path = "/Widgets" + path;
  }

  QgsDebugMsg( "path final = " + path );
  bool on = !itemChecked( path );

  QgsDebugMsg( QString( "on = %1" ).arg( on ) );

  setItemChecked( path, on );
  QTreeWidgetItem *myItem = item( path );
  if ( myItem )
  {
    treeWidget->scrollToItem( myItem, QAbstractItemView::PositionAtCenter );
    treeWidget->clearSelection();
    myItem->setSelected( true );

    QString style;
    if ( !on )
    {
      style = "background-color: #FFCCCC;";
    }
    widget->setStyleSheet( style );
  }

  return true;
}
Ejemplo n.º 7
0
void SidebarWidget::optionChanged(const QString &option, const QVariant &value)
{
	if (option == QLatin1String("Sidebar/CurrentPanel"))
	{
		selectPanel(value.toString());
	}
	else if (option == QLatin1String("Sidebar/Panels"))
	{
		qDeleteAll(m_buttons.begin(), m_buttons.end());

		m_buttons.clear();

		QMenu *menu = new QMenu(m_ui->panelsButton);
		const QStringList chosenPanels = value.toStringList();
		QStringList allPanels;
		allPanels << QLatin1String("bookmarks") << QLatin1String("cache") << QLatin1String("cookies") << QLatin1String("config") << QLatin1String("history") << QLatin1String("notes") << QLatin1String("transfers");

		for (int i = 0; i < allPanels.count(); ++i)
		{
			QAction *action = new QAction(menu);
			action->setCheckable(true);
			action->setChecked(chosenPanels.contains(allPanels[i]));
			action->setData(allPanels[i]);
			action->setText(getPanelTitle(allPanels[i]));

			connect(action, SIGNAL(toggled(bool)), this, SLOT(choosePanel(bool)));

			menu->addAction(action);
		}

		menu->addSeparator();

		for (int i = 0; i < chosenPanels.count(); ++i)
		{
			QToolButton *button = new QToolButton(this);
			button->setDefaultAction(new QAction(button));
			button->setToolTip(getPanelTitle(chosenPanels.at(i)));
			button->setCheckable(true);
			button->setAutoRaise(true);
			button->defaultAction()->setData(chosenPanels.at(i));

			if (chosenPanels.at(i) == QLatin1String("bookmarks"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("bookmarks")));
			}
			else if (chosenPanels.at(i) == QLatin1String("cache"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("cache")));
			}
			else if (chosenPanels.at(i) == QLatin1String("config"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("configuration")));
			}
			else if (chosenPanels.at(i) == QLatin1String("cookies"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("cookies")));
			}
			else if (chosenPanels.at(i) == QLatin1String("history"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("view-history")));
			}
			else if (chosenPanels.at(i) == QLatin1String("notes"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("notes")));
			}
			else if (chosenPanels.at(i) == QLatin1String("transfers"))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("transfers")));
			}
			else if (chosenPanels.at(i).startsWith(QLatin1String("web:")))
			{
				button->setIcon(ThemesManager::getIcon(QLatin1String("text-html")));

				QAction *action = new QAction(menu);
				action->setCheckable(true);
				action->setChecked(true);
				action->setData(chosenPanels.at(i));
				action->setText(getPanelTitle(chosenPanels.at(i)));

				connect(action, SIGNAL(toggled(bool)), this, SLOT(choosePanel(bool)));

				menu->addAction(action);
			}
			else
			{
Ejemplo n.º 8
0
BlenderColorSelector::BlenderColorSelector(QWidget * parent)
    : ColorSelector(parent)
{
    m_highlighterGradientSelector = new HighlighterGradientSelector(this);

    m_highlighterGradientSelector->setColors(ColorUtil::DEFAULT_COLOR, ColorUtil::complementColor(ColorUtil::DEFAULT_COLOR));

    QToolButton * buttonAppendFirstQuarterRegion = new QToolButton(m_highlighterGradientSelector);
    QToolButton * buttonAppendSecondQuarterRegion = new QToolButton(m_highlighterGradientSelector);
    QToolButton * buttonAppendThirdQuarterRegion = new QToolButton(m_highlighterGradientSelector);
    QToolButton * buttonAppendFourthQuarterRegion = new QToolButton(m_highlighterGradientSelector);
    QToolButton * buttonAppendFirstRegion = new QToolButton(m_highlighterGradientSelector);
    QToolButton * buttonAppendSecondRegion = new QToolButton(m_highlighterGradientSelector);
    QToolButton * buttonAppendEntireRegion = new QToolButton(m_highlighterGradientSelector);

//     buttonAppendFirstQuarterRegion->setAutoRaise(true);
//     buttonAppendSecondQuarterRegion->setAutoRaise(true);
//     buttonAppendThirdQuarterRegion->setAutoRaise(true);
//     buttonAppendFourthQuarterRegion->setAutoRaise(true);
//     buttonAppendFirstRegion->setAutoRaise(true);
//     buttonAppendSecondRegion->setAutoRaise(true);
//     buttonAppendEntireRegion->setAutoRaise(true);

    buttonAppendFirstQuarterRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));
    buttonAppendSecondQuarterRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));
    buttonAppendThirdQuarterRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));
    buttonAppendFourthQuarterRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));
    buttonAppendFirstRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));
    buttonAppendSecondRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));
    buttonAppendEntireRegion->setDefaultAction(new KAction(KIcon("list-add"), QString(), this));

    QHBoxLayout * quartersLayout = new QHBoxLayout();
    quartersLayout->addWidget(buttonAppendFirstQuarterRegion);
    quartersLayout->addWidget(buttonAppendSecondQuarterRegion);
    quartersLayout->addWidget(buttonAppendThirdQuarterRegion);
    quartersLayout->addWidget(buttonAppendFourthQuarterRegion);

    QHBoxLayout * halfsLayout = new QHBoxLayout();
    halfsLayout->addWidget(buttonAppendFirstRegion);
    halfsLayout->addWidget(buttonAppendSecondRegion);

    QHBoxLayout * entireRegionLayout = new QHBoxLayout();
    entireRegionLayout->addWidget(buttonAppendEntireRegion);

    QVBoxLayout * mixerLayout = new QVBoxLayout(m_highlighterGradientSelector);
    mixerLayout->addLayout(quartersLayout);
    mixerLayout->addLayout(halfsLayout);
    mixerLayout->addLayout(entireRegionLayout);

    m_firstColor = new KColorButton(this);
    m_firstColor->setMinimumHeight(100);
    m_firstColor->setMaximumWidth(64);
    m_firstColor->setColor(ColorUtil::DEFAULT_COLOR);

    m_secondColor = new KColorButton(this);
    m_secondColor->setMinimumHeight(100);
    m_secondColor->setMaximumWidth(64);
    m_secondColor->setColor(ColorUtil::complementColor(ColorUtil::DEFAULT_COLOR));

    QHBoxLayout * layout = new QHBoxLayout(this);
    layout->addWidget(m_firstColor);
    layout->addWidget(m_highlighterGradientSelector);
    layout->addWidget(m_secondColor);

    connect(m_highlighterGradientSelector, SIGNAL( valueChanged(int) ), this, SLOT( updateMixWhenChangeBias(int) ));

    connect(m_firstColor , SIGNAL( changed(QColor) ), this, SLOT( updateMixWhenChangeColor(QColor) ));
    connect(m_secondColor, SIGNAL( changed(QColor) ), this, SLOT( updateMixWhenChangeColor(QColor) ));

    connect(buttonAppendFirstQuarterRegion->defaultAction() , SIGNAL( hovered() ), SLOT( highlightFirstQuarterRegion()  ));
    connect(buttonAppendSecondQuarterRegion->defaultAction(), SIGNAL( hovered() ), SLOT( highlightSecondQuarterRegion() ));
    connect(buttonAppendThirdQuarterRegion->defaultAction() , SIGNAL( hovered() ), SLOT( highlightThirdQuarterRegion()  ));
    connect(buttonAppendFourthQuarterRegion->defaultAction(), SIGNAL( hovered() ), SLOT( highlightFourthQuarterRegion() ));
    connect(buttonAppendFirstRegion->defaultAction()        , SIGNAL( hovered() ), SLOT( highlightFirstRegion()     ));
    connect(buttonAppendSecondRegion->defaultAction()       , SIGNAL( hovered() ), SLOT( highlightSecondRegion()    ));
    connect(buttonAppendEntireRegion->defaultAction()       , SIGNAL( hovered() ), SLOT( highlightEntireRegion()        ));

    connect(buttonAppendFirstQuarterRegion->defaultAction() , SIGNAL( triggered(bool) ), SLOT( appendFirstQuarterRegion()  ));
    connect(buttonAppendSecondQuarterRegion->defaultAction(), SIGNAL( triggered(bool) ), SLOT( appendSecondQuarterRegion() ));
    connect(buttonAppendThirdQuarterRegion->defaultAction() , SIGNAL( triggered(bool) ), SLOT( appendThirdQuarterRegion()  ));
    connect(buttonAppendFourthQuarterRegion->defaultAction(), SIGNAL( triggered(bool) ), SLOT( appendFourthQuarterRegion() ));
    connect(buttonAppendFirstRegion->defaultAction()        , SIGNAL( triggered(bool) ), SLOT( appendFirstRegion()     ));
    connect(buttonAppendSecondRegion->defaultAction()       , SIGNAL( triggered(bool) ), SLOT( appendSecondRegion()    ));
    connect(buttonAppendEntireRegion->defaultAction()       , SIGNAL( triggered(bool) ), SLOT( appendEntireRegion()        ));
}