Exemple #1
0
QWidget* ToolAction::createWidget( QWidget *parent )
{
    QToolBar *toolBar = qobject_cast< QToolBar * >( parent );
    if ( !toolBar )
        return 0;

    QToolButton *button = new QToolButton( toolBar );
    button->setAutoRaise( true );
    button->setFocusPolicy( Qt::NoFocus );
    button->setIconSize( toolBar->iconSize() );
    button->setToolButtonStyle( toolBar->toolButtonStyle() );
    button->setPopupMode( QToolButton::DelayedPopup );
    button->setMenu( new QMenu( button ) );
    button->setCheckable( true );
    connect(toolBar, &QToolBar::iconSizeChanged, button, &QToolButton::setIconSize);
    connect(toolBar, &QToolBar::toolButtonStyleChanged, button, &QToolButton::setToolButtonStyle);
    connect(button, &QToolButton::triggered, toolBar, &QToolBar::actionTriggered);
    connect( button->menu(), &QMenu::triggered, this, &ToolAction::slotNewDefaultAction );

    m_buttons.append( button );

    if ( !m_actions.isEmpty() )
    {
        button->setDefaultAction( m_actions.first() );
        foreach ( QAction *action, m_actions )
        {
            button->menu()->addAction( action );
            if ( action->isChecked() )
                button->setDefaultAction( action );
        }
Exemple #2
0
QToolBar* MainWindow::createFormatToolBar()
{
    QToolBar *pFormatBar = new QToolBar();
    pFormatBar->setWindowTitle( "Format Bar" );

    m_pCmbFont = new QFontComboBox;
    m_pCmbFont->setEditable( false );
    m_pCmbFont->setFocusPolicy( Qt::NoFocus );
    m_pCmbFontPointSize = new QComboBox;
    updateFontPointSize( m_pCmbFont->currentText() );
    m_pCmbFontPointSize->setFocusPolicy( Qt::NoFocus );
    QToolButton *pBtnMoreOptions = new QToolButton;
    pBtnMoreOptions->setText( "More..." );
    pBtnMoreOptions->setStyleSheet( "border: 1px solid #000000" );
    pBtnMoreOptions->setFixedHeight( 20 );
    pBtnMoreOptions->setFocusPolicy( Qt::NoFocus );

    pFormatBar->addWidget( m_pCmbFont );
    pFormatBar->addWidget( m_pCmbFontPointSize );
    pFormatBar->addWidget( pBtnMoreOptions );

    connect( m_pCmbFont, SIGNAL(currentIndexChanged(int)), this, SLOT(onFontFamilyChanged()) );
    connect( m_pCmbFontPointSize, SIGNAL(currentIndexChanged(int)), this, SLOT(onFontPointSizeChanged()) );
    connect( pBtnMoreOptions, SIGNAL(clicked()), this, SLOT(onFormatMoreBtnClicked()) );

    return pFormatBar;
}
QWidget *KToolBarPopupAction::createWidget(QWidget *_parent)
{
    QToolBar *parent = qobject_cast<QToolBar *>(_parent);
    if (!parent) {
        return QWidgetAction::createWidget(_parent);
    }
    QToolButton *button = new QToolButton(parent);
    button->setAutoRaise(true);
    button->setFocusPolicy(Qt::NoFocus);
    button->setIconSize(parent->iconSize());
    button->setToolButtonStyle(parent->toolButtonStyle());
    button->setDefaultAction(this);

    connect(parent, &QToolBar::iconSizeChanged,
            button, &QAbstractButton::setIconSize);
    connect(parent, &QToolBar::toolButtonStyleChanged,
            button, &QToolButton::setToolButtonStyle);
    connect(button, &QToolButton::triggered,
            parent, &QToolBar::actionTriggered);

    if (d->delayed)
        if (d->stickyMenu) {
            button->setPopupMode(QToolButton::MenuButtonPopup);
        } else {
            button->setPopupMode(QToolButton::DelayedPopup);
        }
    else {
        button->setPopupMode(QToolButton::InstantPopup);
    }

    return button;
}
WNavigationTreeCaption::WNavigationTreeCaption()
	{
	QToolButton * pwButtonUndock = new QToolButton(this);
	pwButtonUndock->setToolTip("Float / Unfloat");
	#if 1
	pwButtonUndock->setStyleSheet("QToolButton { border: none; padding: 3px; }");
	#else
	pwButtonUndock->setStyleSheet("QToolButton { border: none; padding: 0px; }");
	#endif
	QPixmap oPixmap = style()->standardPixmap(QStyle::SP_TitleBarNormalButton);
	pwButtonUndock->setIcon(oPixmap);
//	pwButtonUndock->setMaximumSize(oPixmap.size());
	pwButtonUndock->setCursor(Qt::ArrowCursor);
	pwButtonUndock->setFocusPolicy(Qt::ClickFocus);

	QHBoxLayout * layout = new QHBoxLayout(this);
	layout->setMargin(0);
//	layout->setSpacing(10);
//	layout->addStretch();
	#if 0
	layout->addWidget(g_pwButtonStatusOfNavigationTree, Qt::AlignLeft | Qt::AlignHCenter);
	#endif
	layout->addWidget(g_pwButtonSwitchProfile); // , Qt::AlignLeft | Qt::AlignHCenter);
	//layout->addWidget(new QWidget);
	layout->addStretch();
	//layout->addWidget(pwButtonUndock, Qt::AlignRight | Qt::AlignHCenter);
	layout->addWidget(pwButtonUndock);
	setLayout(layout);
	connect(pwButtonUndock, SIGNAL(clicked()), g_pwNavigationTree, SLOT(SL_ToggleDocking()));
	setCursor(Qt::OpenHandCursor);		// This cursor shows to the user he/she may drag the widget to undock the Navigation Tree
	}
Exemple #5
0
/*!
  \internal
  \brief Creates a tool button using given action.
  This action will set as the default action instead of adding into its action list.
  @return the pointer to a QToolButton instance by "new" operation
 */
QToolButton * Ui::MainWindow::createToolButton(QAction *action, QWidget *parent /* = 0 */)
{
    QToolButton *button = new QToolButton(parent);
    button->setDefaultAction(action);
    button->setAutoRaise(true);
    button->setFocusPolicy(Qt::NoFocus);
    return button;
}
QToolButton* KexiRecordNavigator::createAction(const KGuiItem& item)
{
    QToolButton *toolButton;
    d->lyr->addWidget(toolButton = new KexiSmallToolButton(item.icon(), QString(), this), 0, Qt::AlignVCenter);
    toolButton->setFocusPolicy(Qt::NoFocus);
    toolButton->setToolTip(item.toolTip());
    toolButton->setWhatsThis(item.whatsThis());
    return toolButton;
}
void UIDesktopPanePrivate::prepareErrorPane()
{
    if (m_pErrBox)
        return;

    /* Create error pane: */
    m_pErrBox = new QWidget;

    /* Create main layout: */
    QVBoxLayout *pMainLayout = new QVBoxLayout(m_pErrBox);
#if   defined(VBOX_WS_MAC)
    pMainLayout->setContentsMargins(4, 5, 5, 5);
#elif defined(VBOX_WS_WIN)
    pMainLayout->setContentsMargins(3, 5, 5, 0);
#elif defined(VBOX_WS_X11)
    pMainLayout->setContentsMargins(0, 5, 5, 5);
#endif
    pMainLayout->setSpacing(10);

    /* Create error label: */
    m_pErrLabel = new QLabel(m_pErrBox);
    m_pErrLabel->setWordWrap(true);
    m_pErrLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    pMainLayout->addWidget(m_pErrLabel);

    /* Create error text-browser: */
    m_pErrText = new QTextBrowser(m_pErrBox);
    m_pErrText->setFocusPolicy(Qt::StrongFocus);
    m_pErrText->document()->setDefaultStyleSheet("a { text-decoration: none; }");
    pMainLayout->addWidget(m_pErrText);

    /* If refresh action was set: */
    if (m_pRefreshAction)
    {
        /* Create refresh button: */
        m_pRefreshButton = new QToolButton(m_pErrBox);
        m_pRefreshButton->setFocusPolicy(Qt::StrongFocus);

        /* Create refresh button layout: */
        QHBoxLayout *pButtonLayout = new QHBoxLayout;
        pMainLayout->addLayout(pButtonLayout);
        pButtonLayout->addStretch();
        pButtonLayout->addWidget(m_pRefreshButton);

        /* Connect refresh button: */
        connect(m_pRefreshButton, SIGNAL(clicked()), m_pRefreshAction, SIGNAL(triggered()));
    }

    pMainLayout->addStretch();

    /* Add into the stack: */
    addWidget(m_pErrBox);

    /* Retranslate finally: */
    retranslateUi();
}
QToolButton *
PlayerWidget::createToolButton(QWidget *parent, const char *name, int size)
{
	QToolButton *toolButton = new QToolButton(parent);
	toolButton->setObjectName(name);
	toolButton->setMinimumSize(size, size);
	toolButton->setIconSize(size >= 32 ? QSize(size - 6, size - 6) : QSize(size, size));
	toolButton->setAutoRaise(true);
	toolButton->setFocusPolicy(Qt::NoFocus);
	return toolButton;
}
Exemple #9
0
QAbstractButton *StartTab::addShortcut(const QString &name, const QIcon &icon, QWidget *parent)
{
	// QPushButton has visual problems with big icons
	QToolButton *button = new QToolButton(parent);
	button->setText(name);
	button->setIcon(icon);
	button->setFocusPolicy(Qt::NoFocus);
	button->setIconSize(QSize(48, 48));
	button->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
	button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	return button;
}
void NBOdfOgle::createGUI() {

	QHBoxLayout *lblBtnLyt = new QHBoxLayout();
	QVBoxLayout *widgetLyt = new QVBoxLayout();
	QVBoxLayout *baseLyt = new QVBoxLayout();

	QLabel *lbl = new QLabel( "<tt><b>" + path + "</b></tt>" );

	QToolButton *openBtn = new QToolButton();
	openBtn->setIcon( QIcon( ":/icons/maximize.png" ) );
	openBtn->setAutoRaise( true );
	openBtn->setFocusPolicy( Qt::NoFocus );

	QWidget *baseWidget = new QWidget();
	baseWidget->setObjectName( tr( "guiBase" ) );

	connect( openBtn, SIGNAL( clicked() ), this, SLOT( openInExternal() ) );

	peekWidgetBase = new QTextBrowser();

	// Some basic settings
	peekWidgetBase->setTabStopWidth( 9 * 4 );
	peekWidgetBase->setFont( QFont( "Courier 10 Pitch", 9 ) );
	peekWidgetBase->setAlignment( Qt::AlignLeft );
	peekWidgetBase->setAcceptRichText( false );
	peekWidgetBase->setReadOnly( true );

	// Remove Horizontal Scrollbar, put a Vertical one
	peekWidgetBase->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
	peekWidgetBase->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );

	// Enable word wrap
	peekWidgetBase->setWordWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );
	peekWidgetBase->setObjectName( tr( "previewBase" ) );

	lblBtnLyt->addWidget( lbl );
	lblBtnLyt->addStretch( 0 );
	lblBtnLyt->addWidget( openBtn );

	widgetLyt->addLayout( lblBtnLyt );
	widgetLyt->addWidget( peekWidgetBase );

	baseWidget->setLayout( widgetLyt );
	baseLyt->addWidget( baseWidget );
	baseLyt->setContentsMargins( 0, 0, 0, 0 );

	setLayout( baseLyt );
	peekWidgetBase->setFocus();
};
    QToolButton *addToolButton(QString const &label, QIcon const &icon)
    {
        QToolButton *tb = new QToolButton;
        tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
        tb->setFocusPolicy(Qt::NoFocus);
        tb->setText(label);
        tb->setIcon(icon);
        tb->setCheckable(true);
#ifdef MACOSX
        // Tighter spacing, please.
        tb->setStyleSheet("padding-bottom:-5px");
#endif
        tools->addWidget(tb);
        return tb;
    }
void SideBarGroup::addAction(QAction* action)
{
    int size = KIconLoader::global()->currentSize(KIconLoader::Small);
    QToolButton* button = new SideBarButton();
    button->setFocusPolicy(Qt::NoFocus);
    button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    button->setAutoRaise(true);
    button->setDefaultAction(action);
    button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    button->setIconSize(QSize(size, size));
    if (action->menu()) {
        button->setPopupMode(QToolButton::InstantPopup);
    }
    addWidget(button);
}
ActionOptionWidget::ActionOptionWidget(CellToolBase* cellTool, const QDomElement& e, QWidget *parent) :
    QWidget(parent)
{
    QString name = e.attribute("name");
    setObjectName(name);
    setWindowTitle(i18n(name.toLatin1()));

    QLayout* layout = new GroupFlowLayout(this);//QBoxLayout(QBoxLayout::TopToBottom, this);

    for (QDomElement group = e.firstChildElement("group"); !group.isNull(); group = group.nextSiblingElement("group")) {
        QHBoxLayout *groupLayout = new QHBoxLayout();
        layout->addItem(groupLayout);

        // In each group there are a number of actions that will be layouted together.
        for (QDomElement action = group.firstChildElement("action"); !action.isNull(); action = action.nextSiblingElement("action")) {
            QString actionName = action.attribute("name");
            QAction* a = cellTool->action(actionName);
            if (!a) {
                kWarning() << "unknown action" << actionName << "in CellToolOptionWidgets.xml";
                continue;
            }
            QWidget* w = qobject_cast<QWidgetAction*>(a) ? qobject_cast<QWidgetAction*>(a)->requestWidget(this) : 0;
            if (w && w->inherits("QFontComboBox")) {
                w->setMinimumWidth(w->minimumWidth() / 2);
            }
            if (!w) {
                QToolButton* b = new QToolButton(this);
                b->setFocusPolicy(Qt::NoFocus);
                b->setDefaultAction(a);
                w = b;
            }

            if (w) {
                groupLayout->addWidget(w);
            }
        }
    }

    // The following widget activates a special feature in the
    // ToolOptionsDocker that makes the components of the widget align
    // to the top if there is extra space.
    QWidget *specialSpacer = new QWidget(this);
    specialSpacer->setObjectName("SpecialSpacer");
    layout->addWidget(specialSpacer);
}
void ZLQtApplicationWindow::addToolbarItem(ZLToolbar::ItemPtr item) {
	QToolBar *tb = toolbar(type(*item));
	QAction *action = 0;

	switch (item->type()) {
		case ZLToolbar::Item::PLAIN_BUTTON:
		case ZLToolbar::Item::TOGGLE_BUTTON:
			action = new ZLQtToolBarAction(this, (ZLToolbar::AbstractButtonItem&)*item);
			tb->addAction(action);
			break;
		case ZLToolbar::Item::MENU_BUTTON:
		{
			ZLToolbar::MenuButtonItem &buttonItem = (ZLToolbar::MenuButtonItem&)*item;
			QToolButton *button = new QToolButton(tb);
			button->setFocusPolicy(Qt::NoFocus);
			button->setDefaultAction(new ZLQtToolBarAction(this, buttonItem));
			button->setMenu(new QMenu(button));
			button->setPopupMode(QToolButton::MenuButtonPopup);
			action = tb->addWidget(button);
			myMenuButtons[&buttonItem] = button;
			shared_ptr<ZLPopupData> popupData = buttonItem.popupData();
			myPopupIdMap[&buttonItem] =
				popupData.isNull() ? (size_t)-1 : (popupData->id() - 1);
			break;
		}
		case ZLToolbar::Item::TEXT_FIELD:
		case ZLToolbar::Item::SEARCH_FIELD:
		{
			ZLToolbar::ParameterItem &textFieldItem =
				(ZLToolbar::ParameterItem&)*item;
			LineEditParameter *para = new LineEditParameter(tb, *this, textFieldItem);
			addVisualParameter(textFieldItem.parameterId(), para);
			action = para->action();
			break;
		}
		case ZLToolbar::Item::SEPARATOR:
			action = tb->addSeparator();
			break;
	}

	if (action != 0) {
		myActions[&*item] = action;
	}
}
FilterWidget::FilterWidget(QWidget *parent)
    : QLineEdit(parent)
    , m_patternGroup(new QActionGroup(this))
{
    setClearButtonEnabled(true);
    connect(this, SIGNAL(textChanged(QString)), this, SIGNAL(filterChanged()));

    QMenu *menu = new QMenu(this);
    m_caseSensitivityAction = menu->addAction(tr("Case Sensitive"));
    m_caseSensitivityAction->setCheckable(true);
    connect(m_caseSensitivityAction, SIGNAL(toggled(bool)), this, SIGNAL(filterChanged()));

    menu->addSeparator();
    m_patternGroup->setExclusive(true);
    QAction *patternAction = menu->addAction("Fixed String");
    patternAction->setData(QVariant(int(QRegExp::FixedString)));
    patternAction->setCheckable(true);
    patternAction->setChecked(true);
    m_patternGroup->addAction(patternAction);
    patternAction = menu->addAction("Regular Expression");
    patternAction->setCheckable(true);
    patternAction->setData(QVariant(int(QRegExp::RegExp2)));
    m_patternGroup->addAction(patternAction);
    patternAction = menu->addAction("Wildcard");
    patternAction->setCheckable(true);
    patternAction->setData(QVariant(int(QRegExp::Wildcard)));
    m_patternGroup->addAction(patternAction);
    connect(m_patternGroup, SIGNAL(triggered(QAction*)), this, SIGNAL(filterChanged()));

    const QIcon icon = QIcon(QPixmap(":/images/find.png"));
    QToolButton *optionsButton = new QToolButton;
#ifndef QT_NO_CURSOR
    optionsButton->setCursor(Qt::ArrowCursor);
#endif
    optionsButton->setFocusPolicy(Qt::NoFocus);
    optionsButton->setStyleSheet("* { border: none; }");
    optionsButton->setIcon(icon);
    optionsButton->setMenu(menu);
    optionsButton->setPopupMode(QToolButton::InstantPopup);

    QWidgetAction *optionsAction = new QWidgetAction(this);
    optionsAction->setDefaultWidget(optionsButton);
    addAction(optionsAction, QLineEdit::LeadingPosition);
}
MediaSearchWidget::MediaSearchWidget(QWidget *parent) :
    QWidget(parent)
{
//    m_animate = new StateMachineServer;

    this->setMinimumSize(160, 20);
    this->setFixedSize(160, 20);

    m_searchKeyEdit = new QLineEdit;
    m_searchKeyEdit->setText( tr("Searching...") );

    QToolButton* searchBtn = new QToolButton;

    QSize size = QSize( 20, this->size().height() );
    searchBtn->setMinimumSize(size);
    searchBtn->setMaximumSize(size);
    searchBtn->setIconSize(size);
    searchBtn->setIcon( QIcon(":/images/Button-search.png"));
    searchBtn->setFocusPolicy(Qt::NoFocus);// 得到焦点时,不显示虚线框
    searchBtn->setCursor(QCursor(Qt::PointingHandCursor));

    QHBoxLayout *editLayout = new QHBoxLayout();
    editLayout->setContentsMargins(0, 0, 0, 0);
    editLayout->addStretch();
    editLayout->addWidget(searchBtn);
    m_searchKeyEdit->setLayout(editLayout);
    // 设置输入框中文件输入区,不让输入的文字在被隐藏在按钮下
    m_searchKeyEdit->setTextMargins(0, 1, size.width(), 1);

    QHBoxLayout* hLayout = new QHBoxLayout;
    hLayout->setContentsMargins(0,0,0,0);
    hLayout->setSpacing(4);
    hLayout->addWidget(m_searchKeyEdit);
    hLayout->setAlignment(Qt::AlignLeft);
    this->setLayout(hLayout);

    connect(searchBtn, SIGNAL(clicked()), this, SLOT(searchMusic()) );
//    connect(this, SIGNAL(animateHide()), m_animate, SIGNAL(transHide()) );
//    /connect(this, SIGNAL(animateShow()), m_animate, SIGNAL(transShow()) );

}
Exemple #17
0
/*
 * The constructor.  The central button is optional, centerIcon and centerTip are the
 * icon and tooltip for it and can be NULL.  size specifies the size of the buttons.
 * The autoRaise flag is used to set whether the buttons autoraise.  A step size label
 * is optional and provided if stepSize >= 0.
 */
RotationTool::RotationTool(QWidget *parent, QIcon *centerIcon, const char *centerTip, 
                           int size, bool autoRaise, float stepSize)
  : QWidget(parent)
{
  int ind, row, col;
  mStepLabel = NULL;
  mCenterBut = NULL;
  if (sFirstTime) {
    for (ind = 0; ind < 8; ind++) {
      sIcons[ind] = new QIcon();
      sIcons[ind]->addFile(QString(sFileList[ind]), QSize(size - 4, size - 4));
    }
  }

  QHBoxLayout *hLayout = new QHBoxLayout(this);
  hLayout->setContentsMargins(0, 0, 0, 0);
  hLayout->setSpacing(0);
  QVBoxLayout *vLayout = new QVBoxLayout();
  hLayout->addLayout(vLayout);
  vLayout->setContentsMargins(0, 0, 0, 0);
  vLayout->setSpacing(2);
  hLayout->addStretch();

  // Make the grid and the signal mapper
  QGridLayout *grid = new QGridLayout();
  vLayout->addLayout(grid);
  grid->setContentsMargins(0, 0, 0, 0);
  grid->setSpacing(autoRaise ? 0 : 4);

  QSignalMapper *rotMapper = new QSignalMapper(this);
  connect(rotMapper, SIGNAL(mapped(int)), this, SLOT(buttonClicked(int)));

  // Fill the grid
  ind = 0;
  for (row = 0; row < 3; row++) {
    for (col = 0; col < 3; col++) {
      QToolButton *button = new QToolButton(this);
      button->setAutoRaise(autoRaise);
      button->setFixedSize(size, size);
      button->setFocusPolicy(Qt::NoFocus);
      grid->addWidget(button, row, col);
      if (col == 1 && row == 1) {

        // Set center toggle button properties
        button->setCheckable(true);
        button->setChecked(false);
        mCenterBut = button;
        if (centerTip)
          button->setToolTip(centerTip);
        if (centerIcon) 
          button->setIcon(*centerIcon);
        connect(mCenterBut, SIGNAL(toggled(bool)), this, SLOT(centerToggled(bool)));
      } else {

        // Set rotation button properties and mapping, and autorepeat for non-step ones
        button->setToolTip(sButtonTips[ind]);
        button->setIcon(*sIcons[ind]);
        rotMapper->setMapping(button, ind);
        connect(button, SIGNAL(clicked()), rotMapper, SLOT(map()));
        if (!sStepSign[ind]) {
          button->setAutoRepeat(true);
          button->setAutoRepeatDelay(300);
          button->setAutoRepeatInterval(100);
        }
        ind++;
      }
    }
Exemple #18
0
void ChartWidget::setupWidgets()
{
	m_buttons = new QWidget(this);

	QHBoxLayout* tblayout = new QHBoxLayout;
	tblayout->addItem(new QSpacerItem(15, 10, QSizePolicy::Fixed, QSizePolicy::Fixed));
	tblayout->addWidget(new QLabel(tr("Timebase:")));
	tblayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed));
	m_lblSecondsPerDivision = new QLabel();
	tblayout->addWidget(m_lblSecondsPerDivision);

	tblayout->addSpacing(15);

	QToolButton* tbtn;

	tbtn = new QToolButton;
	tbtn->setDefaultAction(m_mainS->actions()->viewZoomIn);
	tbtn->setFocusPolicy(Qt::NoFocus);
	tblayout->addWidget(tbtn);
	m_btnZoomIn = tbtn;

	tbtn = new QToolButton;
	tbtn->setDefaultAction(m_mainS->actions()->viewZoomOut);
	tbtn->setFocusPolicy(Qt::NoFocus);
	tblayout->addWidget(tbtn);
	m_btnZoomOut = tbtn;

	tbtn = new QToolButton;
	tbtn->setDefaultAction(m_mainS->actions()->viewZoomFull);
	tbtn->setFocusPolicy(Qt::NoFocus);
	tblayout->addWidget(tbtn);
	tblayout->addItem(new QSpacerItem(10, 10, QSizePolicy::Expanding, QSizePolicy::Fixed));
	m_btnZoomFull = tbtn;

	m_buttons->setLayout(tblayout);

	m_scrollbar = new QScrollBar(Qt::Horizontal, this);
	m_scrollbar->setSingleStep(EAD_SAMPLES_PER_SECOND);

	m_buttons->setCursor(Qt::ArrowCursor);
	m_scrollbar->setCursor(Qt::ArrowCursor);

	// Set fixed size for m_lblSecondsPerDivision
	int nWidth = 0;
	for (int i = 0; ChartScope::anSecondsPerDivision[i] > 0; i++)
	{
		QString s = timestampString(ChartScope::anSecondsPerDivision[i]);
		nWidth = qMax(nWidth, m_lblSecondsPerDivision->fontMetrics().width(s));
	}
	m_lblSecondsPerDivision->setMinimumWidth(nWidth);
	m_lblSecondsPerDivision->setText(m_chartS->timebaseString());

	m_lblRecording = new QLabel(tr("  RECORDING: 99.99 "), this);
	m_lblRecording->setStyleSheet(
		"background-color: #fdd;"
		"border-style: outset;"
		"border-width: 1px;"
		"border-color: #500;"
		"font-weight: bold;"
		"padding: 5px 10px;");
	m_lblRecording->setVisible(false);
}
Exemple #19
0
LMaster::LMaster(QWidget* parent, const char* name)
   : MidiEditor(TopWin::LMASTER, 0, 0, parent, name)
      {
      pos_editor = 0;
      tempo_editor = 0;
      sig_editor = 0;
      key_editor = 0;
      editedItem = 0;
      editingNewItem = false;
      setWindowTitle(tr("MusE: Mastertrack"));
      setMinimumHeight(100);
      //setFixedWidth(400);            // FIXME: Arbitrary. But without this, sig editor is too wide. Must fix sig editor width...
      setFocusPolicy(Qt::NoFocus);


      comboboxTimer=new QTimer(this);
      comboboxTimer->setInterval(150);
      comboboxTimer->setSingleShot(true);
      connect(comboboxTimer, SIGNAL(timeout()), this, SLOT(comboboxTimerSlot()));


      //---------Pulldown Menu----------------------------
      menuEdit = menuBar()->addMenu(tr("&Edit"));
      QSignalMapper *signalMapper = new QSignalMapper(this);
      menuEdit->addActions(MusEGlobal::undoRedo->actions());
      menuEdit->addSeparator();
      tempoAction = menuEdit->addAction(tr("Insert Tempo"));
      signAction = menuEdit->addAction(tr("Insert Signature"));
      keyAction = menuEdit->addAction(tr("Insert Key"));
      posAction = menuEdit->addAction(tr("Edit Position"));
      valAction = menuEdit->addAction(tr("Edit Value"));
      delAction = menuEdit->addAction(tr("Delete Event"));
      delAction->setShortcut(Qt::Key_Delete);

      QMenu* settingsMenu = menuBar()->addMenu(tr("Window &Config"));
      settingsMenu->addAction(subwinAction);
      settingsMenu->addAction(shareAction);
      settingsMenu->addAction(fullscreenAction);

      
      connect(tempoAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
      connect(signAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
      connect(keyAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
      connect(posAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
      connect(valAction, SIGNAL(triggered()), signalMapper, SLOT(map()));
      connect(delAction, SIGNAL(triggered()), signalMapper, SLOT(map()));

      signalMapper->setMapping(tempoAction, CMD_INSERT_TEMPO);
      signalMapper->setMapping(signAction, CMD_INSERT_SIG);
      signalMapper->setMapping(keyAction, CMD_INSERT_KEY);
      signalMapper->setMapping(posAction, CMD_EDIT_BEAT);
      signalMapper->setMapping(valAction, CMD_EDIT_VALUE);
      signalMapper->setMapping(delAction, CMD_DELETE);

      connect(signalMapper, SIGNAL(mapped(int)), SLOT(cmd(int)));

      // Toolbars ---------------------------------------------------------
      
      // NOTICE: Please ensure that any tool bar object names here match the names assigned 
      //          to identical or similar toolbars in class MusE or other TopWin classes. 
      //         This allows MusE::setCurrentMenuSharingTopwin() to do some magic
      //          to retain the original toolbar layout. If it finds an existing
      //          toolbar with the same object name, it /replaces/ it using insertToolBar(),
      //          instead of /appending/ with addToolBar().

      addToolBarBreak();
      
      QToolBar* edit = addToolBar(tr("Edit tools"));
      edit->setObjectName("Master List Edit Tools");
      QToolButton* tempoButton = new QToolButton();
      QToolButton* timeSigButton = new QToolButton();
      QToolButton* keyButton = new QToolButton();
      tempoButton->setFocusPolicy(Qt::NoFocus);
      timeSigButton->setFocusPolicy(Qt::NoFocus);
      keyButton->setFocusPolicy(Qt::NoFocus);
      tempoButton->setText(tr("Tempo"));
      timeSigButton->setText(tr("Timesig"));
      keyButton->setText(tr("Key"));
      tempoButton->setToolTip(tr("new tempo"));
      timeSigButton->setToolTip(tr("new signature"));
      keyButton->setToolTip(tr("new key"));
      edit->addWidget(tempoButton);
      edit->addWidget(timeSigButton);
      edit->addWidget(keyButton);
      
      //---------------------------------------------------
      //    master
      //---------------------------------------------------

      view = new QTreeWidget;
      view->setAllColumnsShowFocus(true);
      view->setSelectionMode(QAbstractItemView::SingleSelection);
      QStringList columnnames;
      columnnames << tr("Meter")
                  << tr("Time")
                  << tr("Type")
                  << tr("Value");
      view->setHeaderLabels(columnnames);
      view->setColumnWidth(2,80);
      view->header()->setStretchLastSection(true);

      //---------------------------------------------------
      //    Rest
      //---------------------------------------------------

      mainGrid->setRowStretch(0, 100);
      mainGrid->setColumnStretch(0, 100);

      mainGrid->addWidget(view,  0, 0);
      updateList();

      tempo_editor = new QLineEdit(view->viewport());
      tempo_editor->setFrame(false);
      tempo_editor->hide();
      connect(tempo_editor, SIGNAL(returnPressed()), SLOT(returnPressed()));
      sig_editor = new SigEdit(view->viewport());
      sig_editor->setFrame(false);
      sig_editor->hide();
      connect(sig_editor, SIGNAL(returnPressed()), SLOT(returnPressed()));
      pos_editor = new PosEdit(view->viewport());
      pos_editor->setFrame(false);
      pos_editor->hide();
      connect(pos_editor, SIGNAL(returnPressed()), SLOT(returnPressed()));
      key_editor = new QComboBox(view->viewport());
      key_editor->setFrame(false);
      key_editor->addItems(MusECore::keyStrs);
      key_editor->hide();
      connect(key_editor, SIGNAL(activated(int)), SLOT(returnPressed()));

      connect(view, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(select(QTreeWidgetItem*, QTreeWidgetItem*)));
      connect(view, SIGNAL(itemPressed(QTreeWidgetItem*, int)), SLOT(itemPressed(QTreeWidgetItem*, int)));
      connect(view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(itemDoubleClicked(QTreeWidgetItem*)));
      connect(MusEGlobal::song, SIGNAL(songChanged(MusECore::SongChangedStruct_t)), SLOT(songChanged(MusECore::SongChangedStruct_t)));
      connect(this, SIGNAL(seekTo(int)), MusEGlobal::song, SLOT(seekTo(int)));
      connect(tempoButton, SIGNAL(clicked()), SLOT(tempoButtonClicked()));
      connect(timeSigButton, SIGNAL(clicked()), SLOT(timeSigButtonClicked()));
      connect(keyButton, SIGNAL(clicked()), SLOT(insertKey()));

      initShortcuts();
      finalizeInit();
      }
//FIXME: keep loaded plugins in own plugin manager and
//unload plugins to let load new version without
//the need to restart the application
void RackWindow::loadPlugin(QWidget *pluginHost)
{
    QDir pluginsDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
    if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
        pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
    if (pluginsDir.dirName() == "MacOS") {
        pluginsDir.cdUp();
        pluginsDir.cdUp();
        pluginsDir.cdUp();
    }
#endif

    if (!pluginsDir.cd("plugins"))
    {
        QMessageBox::information(this, "Error", "No plugin folder found");
        return;
    }


    QStringList pluginList = pluginsDir.entryList(QDir::Files);


    RSelectPluginDialog pluginDialog(this);
    pluginDialog.pluginListWidget->addItems(pluginList);
    pluginDialog.pluginListWidget->setCurrentRow(0);
    if (pluginDialog.exec())
    {



//    bool ok;
//    int newPluginIndex = RSelectPluginDialog::getIndex(this, pluginList, &ok);
//    if (ok) {

        //QString fileName = pluginsDir.entryList(QDir::Files).at(newPluginIndex);

        QString fileName = pluginsDir.entryList(QDir::Files).at(pluginDialog.pluginListWidget->currentRow());

        QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
        QObject *plugin = pluginLoader.instance();


        ///test

//        QList<QPluginLoader *> loadedPlugins = findChildren<QPluginLoader *>();

//        QObject *plugin = 0;

//        for (int i = 0; i < loadedPlugins.size(); ++i) {
//            if (loadedPlugins.at(i)->fileName() == pluginsDir.absoluteFilePath(fileName)) {
//                plugin = loadedPlugins.at(i)->instance();
//                break;
//            }
//        }

//        if (!plugin) {
//            QPluginLoader *pluginLoader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName), this);
//            plugin = pluginLoader->instance();
//        }


        //debug code
        qDebug() << "we have the following plugins loaded:";
        QList<QPluginLoader *> debugPlugins = findChildren<QPluginLoader *>();
        for (int i = 0; i < debugPlugins.size(); ++i) {
            qDebug() << debugPlugins.at(i)->fileName();
        }


        //////////


//        m_pluginLoader = new QPluginLoader(pluginsDir.absoluteFilePath(fileName), this);
//        QObject *plugin = m_pluginLoader->instance();

        /////////////////


        if (plugin)
        {
            IWidgetPlugin *widgetPlugin = qobject_cast<IWidgetPlugin *>(plugin);
            if (widgetPlugin)
            {
                QWidget *newWidget = widgetPlugin->createRWidget(m_coreImpl, this);

                //get pointers from pluginhost:
                QStackedWidget *pluginStack = pluginHost->findChild<QStackedWidget *>("rackPluginStack");
                QToolBar *pluginHostToolBar = pluginHost->findChild<QToolBar *>("rackPluginHostToolBar");
                QToolBar *pluginToolBar = pluginHost->property("pluginToolBar").value<QToolBar *>();
                QSignalMapper *sm = pluginHost->findChild<QSignalMapper *>("rackPluginSwitchMapper");
                QActionGroup *ag = pluginHostToolBar->findChild<QActionGroup *>();

                //add plugin widget to the widget stack:
                pluginStack->setCurrentIndex(pluginStack->addWidget(newWidget));

                //create action for the toolbars:
                QAction *act = new QAction(widgetPlugin->name(), ag);
                act->setCheckable(true);
                act->setChecked(true);
                //qt bugfix: set transparent dummy icon to move button text down or right
                act->setIcon(QIcon(":/images/transparent-icon.png"));

                //create button for pluginhost toolbar:
                QToolButton *tb = new QToolButton;
                tb->setObjectName(QLatin1String(newWidget->metaObject()->className()) + "ToolButton");
                tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
                tb->setFocusPolicy(Qt::NoFocus);
                tb->setDefaultAction(act);
                RPushButton *settingsButton = new RPushButton;
                settingsButton->setObjectName("rackPluginHostToolBarSettingsButton");
                RPushButton *deleteButton = new RPushButton;
                deleteButton->setObjectName("rackPluginHostToolBarDeleteButton");
                QHBoxLayout *hl = new QHBoxLayout(tb);
                hl->setSpacing(0);
                hl->setContentsMargins(0,0,1,0);
                hl->addStretch();
                hl->addWidget(settingsButton);
                hl->addWidget(deleteButton);
                pluginHostToolBar->addWidget(tb);

                //create button for plugin toolbar:
                QToolButton *tb1 = new QToolButton;
                tb1->setObjectName(QLatin1String(newWidget->metaObject()->className()) + "ToolButton");
                tb1->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                tb1->setFocusPolicy(Qt::NoFocus);
                tb1->setDefaultAction(act);
                pluginToolBar->addWidget(tb1);

                //connect action trigger to PluginSwitchMapper;
                QObject::connect(act, SIGNAL(triggered()), sm, SLOT(map()));
                sm->setMapping(act, newWidget);

                //connect delete signal
                //remove act from actiongroup and delete it:
                QObject::connect(deleteButton, SIGNAL(clicked()), m_mapperClosePlugin, SLOT(map()));
                m_mapperClosePlugin->setMapping(deleteButton, act);
                QObject::connect(deleteButton, SIGNAL(clicked()), newWidget, SLOT(deleteLater()));
                QObject::connect(deleteButton, SIGNAL(clicked()), tb1, SLOT(deleteLater()));
                QObject::connect(deleteButton, SIGNAL(clicked()), tb, SLOT(deleteLater()));

                //connect settings signal
                //if (plugin has settings) ...
                //QObject::connect(settingsButton, SIGNAL(clicked()),

            }
        }
        else
        {
            QMessageBox::information(this, "Error", "Could not load the plugin");
            qDebug() << pluginLoader.errorString();

        }
    }
}