Ejemplo n.º 1
0
void QgsTabWidget::tabInserted( int index )
{
  if ( !mSetTabVisibleFlag )
  {
    QWidget *newWidget = widget( index );

    if ( index == 0 )
    {
      mTabs.insert( 0, TabInformation( newWidget, tabText( index ) ) );
    }
    else
    {
      bool inserted = false;
      QList<TabInformation>::iterator it;

      for ( it = mTabs.begin(); it != mTabs.end(); ++it )
      {
        if ( it->sourceIndex == index )
        {
          mTabs.insert( it, TabInformation( newWidget, tabText( index ) ) );
          inserted = true;
          break;
        }
      }

      if ( !inserted )
      {
        mTabs.append( TabInformation( newWidget, tabText( index ) ) );
      }
    }
  }

  synchronizeIndexes();
}
Ejemplo n.º 2
0
bool EditorTab::saveFile(int index) 
{
	Editor * editor = (Editor *)widget(index);
	
	QString fileNamemod = tabText(index);
	QChar asterisk = tabText(index).at(0);
	
	if(asterisk == '*' && editor->isModified()) {
		fileNamemod.remove(0, 1);
		this->setTabText(index, fileNamemod);
  }
  
	return editor->Save();
}
Ejemplo n.º 3
0
void MyMdiArea::addSubWindow(MyMdiSubWindow* window)
{
	Q_ASSERT(subWindows_.contains(window) == false);

	currentWidget_->hide();
	layout_->removeWidget(currentWidget_);

	layout_->addWidget(window);
	window->show();
	currentWidget_ = window;

	bool blocked = tabBar_->blockSignals(true);
	tabBar_->addTab(tabText(window));
	tabBar_->setCurrentIndex(tabBar_->count() - 1);
	tabBar_->blockSignals(blocked);

	QWidget* left = tabBar_->tabButton(tabBar_->count() - 1, QTabBar::LeftSide);
	QWidget* right = tabBar_->tabButton(tabBar_->count() - 1, QTabBar::RightSide);

	subWindows_.append(window);

	connect(window, SIGNAL(windowTitleChanged(const QString&)), this, SLOT(onWindowModified()));
	connect(window, SIGNAL(modifiedChanged(bool)), this, SLOT(onWindowModified()));
	connect(window, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*)));

	emit subWindowActivated(activeSubWindow());
}
Ejemplo n.º 4
0
void TabWidget::closeTab(int index)
{
	if(index >= 0)
	{
		emit closeTabRequested(tabText(index));
	}
}
Ejemplo n.º 5
0
void TabBar::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() == Qt::LeftButton) {
#if QT_VERSION >= 0x040500
        int diffX = event->pos().x() - m_dragStartPos.x();
        int diffY = event->pos().y() - m_dragStartPos.y();
#endif
        if ((event->pos() - m_dragStartPos).manhattanLength() > QApplication::startDragDistance()
#if QT_VERSION >= 0x040500
            && diffX < 3 && diffX > -3
            && diffY < -10
#endif
            ) {
            QDrag *drag = new QDrag(this);
            QMimeData *mimeData = new QMimeData;
            QList<QUrl> urls;
            int index = tabAt(event->pos());
            QUrl url = tabData(index).toUrl();
            urls.append(url);
            mimeData->setUrls(urls);
            mimeData->setText(tabText(index));
            mimeData->setData(QLatin1String("action"), "tab-reordering");
            drag->setMimeData(mimeData);
            drag->exec();
        }
    }
    QTabBar::mouseMoveEvent(event);
}
Ejemplo n.º 6
0
void YTTabBar::paintEvent(QPaintEvent *event)
{
    QPainter p(this);
    for(int i=0; i < count(); ++i)
    {
        QRect r = tabRect(i);
        if(i != count() -1)
            r.adjust(0,0, -1, 0);
        if(i == pressedIndex)
        {
            p.drawPixmap(r, clickedPix);
        }
        else if(i == currentIndex())
        {
            p.drawPixmap(r, selectedPix);
        }
        else if(i == hoveredIndex)
        {
            p.drawPixmap(r, hoverPix);
        }
        else
        {
            p.drawPixmap(r, nonSelectedPix);
        }
        if(i != count() -1)
            p.drawPixmap(r.right()+1, r.top(), sepPix.width(), r.height() ,sepPix);
        p.drawText(r, Qt::AlignCenter ,tabText(i) );
    }
}
Ejemplo n.º 7
0
void pTabBar::updateTabsNumber( int i )
{
    // fill i if i = -1 for complete update
    if ( i == -1 )
        i = 0;

    // loop documents starting at id i
    for ( int j = i; j < count(); j++ )
    {
        // only 10 tabs can have shortcut
        if ( j > 9 )
            return;

        // got tab text
        QString s = tabText( j );

        // look index of cut part
        int k = s.indexOf( ":" );

        // set new tab caption
        if ( tabsHaveShortcut() )
            setTabText( j, QString( "&%1: %2" ).arg( j ).arg( s.mid( k != -1 ? k +2 : 0 ) ) );
        else
            setTabText( j, s.mid( k != -1 ? k +2 : 0 ) );
    }
}
Ejemplo n.º 8
0
/** Redefined to display an editable area. */
void TabBar::mouseDoubleClickEvent(QMouseEvent *event)
{
	int tabIndex = tabAt(event->pos());
	int c = currentIndex();
	if (-1 < tabIndex && tabIndex < count() && c == tabIndex) {
		QRect visualRect = tabRect(tabIndex);
		SettingsPrivate *settings = SettingsPrivate::instance();
		if (settings->isRectTabs()) {
			visualRect.setLeft(visualRect.left() + 1);
			visualRect.setRight(visualRect.right() - 1);
		} else {
			visualRect.setLeft(visualRect.left() + 3 + settings->tabsOverlappingLength() * 1.25 + height() / 2);
			visualRect.setRight(visualRect.right() - settings->tabsOverlappingLength());
		}
		visualRect.setTop(visualRect.top() + 1);

		// Disable close buttons in case of unfortunate click
		for (int t = 0; t < count(); t++) {
			QWidget *button = tabButton(t, QTabBar::RightSide);
			if (button && t != tabIndex) {
				button->setEnabled(false);
			}
		}

		// Feed the QLineEdit with current tab text
		lineEdit->setText(tabText(tabIndex));
		lineEdit->selectAll();
		lineEdit->setFocus();
		lineEdit->setGeometry(visualRect);
		lineEdit->setVisible(true);
		lineEdit->grabMouse();
	}
	QTabBar::mouseDoubleClickEvent(event);
}
Ejemplo n.º 9
0
int TabWidget::addTab(Tab *widget, const QString &name, quint32 tabId)
{
    if(!widget->isHometab())
        emit closeHomeTab();

    int idx = QTabWidget::addTab(widget, name);

    installEventFilterToChildren(widget);

    std::vector<quint32>::iterator itr = m_tab_ids.begin() + idx;
    m_tab_ids.insert(itr, tabId);

    setCurrentIndex(idx);
    changeMenu(idx);

    if(count() >= 2)
        m_tab_bar->enableSplit(true);

    if(widget->isWorkTab())
    {
        connect(widget, SIGNAL(statusBarMsg(QString,int)),     SIGNAL(statusBarMsg(QString,int)));
        connect(widget, SIGNAL(setConnId(QString,bool)),       SLOT(setConnString(QString,bool)));
    }
    else if(widget->isChild())
        connect((ChildTab*)widget, SIGNAL(tabText(QString)), SLOT(setTabNameAndTooltip(QString)));
    connect(widget, SIGNAL(activateMe()), SLOT(activateTab()));
    connect(widget, SIGNAL(destroyed()), SLOT(checkEmpty()), Qt::QueuedConnection);

    setTabNameAndTooltip(idx, name);
    setTabsClosable(true);
    return idx;
}
Ejemplo n.º 10
0
void TTabWidget::setTabVisible(int idx, bool visible)
{
    if (hidden_idx.contains(idx) != visible)
        return;

    int bar_idx = idx;
    int vector_idx = 0;
    while (vector_idx < hidden_idx.size() && hidden_idx.at(vector_idx) < idx) {
        bar_idx--;
        vector_idx++;
    }

    if (visible ? vector_idx >= hidden_idx.size() : bar_idx >= count())
        return;

    doing_stuff = true;

    if (!visible) {
        QWidget *wid = widget(bar_idx);
        hidden_wid.insert(vector_idx, wid);
        hidden_idx.insert(vector_idx, idx);
        hidden_data.insert(vector_idx, qMakePair<QIcon, QString>(tabIcon(bar_idx), tabText(bar_idx)));

        removeTab(bar_idx);
        wid->setParent(this);
    } else {
        insertTab(bar_idx, hidden_wid.at(vector_idx), hidden_data.at(vector_idx).first, hidden_data.at(vector_idx).second);

        hidden_wid.remove(vector_idx);
        hidden_idx.remove(vector_idx);
        hidden_data.remove(vector_idx);
    }

    doing_stuff = false;
}
Ejemplo n.º 11
0
bool QtDNDTabBar::event(QEvent* event) {
	QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
	if (mouseEvent) {
		QWidget* childAtPoint = window()->childAt(mapTo(window(), mouseEvent->pos()));
		QtDNDTabBar* underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint);
		if (!underMouse && childAtPoint) {
			underMouse = dynamic_cast<QtDNDTabBar*>(childAtPoint->parent());
		}
		if (!underMouse && currentIndex() >= 0) {
			// detach and drag

			// stop move event
			QMouseEvent* finishMoveEvent = new QMouseEvent (QEvent::MouseMove, mouseEvent->pos (), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
			QTabBar::event(finishMoveEvent);
			delete finishMoveEvent;
			finishMoveEvent = NULL;

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

			// distinguish tab-reordering drops from other ones
			mimeData->setData("action", "application/tab-detach") ;
			drag->setMimeData(mimeData);

			// set drag image
			QRect rect = tabRect( currentIndex() );
#if QT_VERSION >= 0x050000
			QPixmap pixmap = grab(rect);
#else
			QPixmap pixmap = QPixmap::grabWidget(this, rect);
#endif
			QPixmap targetPixmap (pixmap.size ());
			QPainter painter (&targetPixmap);
			painter.setOpacity(0.9);
			painter.drawPixmap(0,0, pixmap);
			painter.end ();
			drag->setPixmap (targetPixmap);

			drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()));

			dragIndex = currentIndex();
			dragText = tabText(dragIndex);
			dragWidget = dynamic_cast<QTabWidget*>(parent())->widget(dragIndex);
			assert(dragWidget);
			dynamic_cast<QTabWidget*>(parent())->removeTab(currentIndex());
			Qt::DropAction dropAction = drag->exec();
			if (dropAction == Qt::IgnoreAction) {
				// aborted drag, put tab back in place
				// disable event handling during the insert for the tab to prevent infinite recursion (stack overflow)
				dragWidget->blockSignals(true);
				dynamic_cast<QTabWidget*>(parent())->insertTab(dragIndex, dragWidget, dragText);
				dragWidget->blockSignals(false);
			}
			return true;
		}
	}
	return QTabBar::event(event);
}
Ejemplo n.º 12
0
void TabWidget::setTabItemCountVisible(bool visible)
{
    m_showTabItemCount = visible;
    for (int i = 0; i < count(); ++i)
        updateTabItemCount( tabText(i) );

    updateSize();
}
Ejemplo n.º 13
0
/*!
    \details Set if tabs have or not a small close button
    \param buttons True for buttons, else false
*/
void pTabBar::setTabsHaveCloseButton( bool buttons )
{
    if ( aToggleTabsHaveCloseButton->isChecked() == buttons && sender() != aToggleTabsHaveCloseButton )
        return;
    aToggleTabsHaveCloseButton->setChecked( buttons );
    setTabText( 0, tabText( 0 ) ); // workaround for tabs update
    emit tabsHaveCloseButtonChanged( aToggleTabsHaveCloseButton->isChecked() );
}
Ejemplo n.º 14
0
void
Unicorn::TabBar::tabInserted( int )
{
    int w = 0;
    for (int i = 0; i < count(); ++i)
        w = qMax( fontMetrics().width( tabText( i ) ), w );
    setMinimumWidth( (m_leftMargin + (count() * ( w + 20 ))) + 10 + layout()->minimumSize().width());
}
Ejemplo n.º 15
0
QStyleOptionTabV2 YaTabBarBase::getStyleOption(int tab) const
{
	QStyleOptionTabV2 opt;
	opt.init(this);
	opt.state &= ~(QStyle::State_HasFocus | QStyle::State_MouseOver);
	opt.rect = tabRect(tab);
	bool isCurrent = tab == currentIndex();
	opt.row = 0;
//    if (tab == pressedIndex)
//        opt.state |= QStyle::State_Sunken;
	if (isCurrent)
		opt.state |= QStyle::State_Selected;
	if (isCurrent && hasFocus())
		opt.state |= QStyle::State_HasFocus;
	if (isTabEnabled(tab))
		opt.state &= ~QStyle::State_Enabled;
	if (isActiveWindow())
		opt.state |= QStyle::State_Active;
//    if (opt.rect == hoverRect)
//        opt.state |= QStyle::State_MouseOver;
	opt.shape = shape();
	opt.text = tabText(tab);

	if (tabTextColor(tab).isValid())
		opt.palette.setColor(foregroundRole(), tabTextColor(tab));

	opt.icon = tabIcon(tab);
	opt.iconSize = opt.icon.actualSize(QSize(32, 32));  // Will get the default value then.

	int totalTabs = count();

	if (tab > 0 && tab - 1 == currentIndex())
		opt.selectedPosition = QStyleOptionTab::PreviousIsSelected;
	else if (tab < totalTabs - 1 && tab + 1 == currentIndex())
		opt.selectedPosition = QStyleOptionTab::NextIsSelected;
	else
		opt.selectedPosition = QStyleOptionTab::NotAdjacent;

	if (tab == 0) {
		if (totalTabs > 1)
			opt.position = QStyleOptionTab::Beginning;
		else
			opt.position = QStyleOptionTab::OnlyOneTab;
	}
	else if (tab == totalTabs - 1) {
		opt.position = QStyleOptionTab::End;
	}
	else {
		opt.position = QStyleOptionTab::Middle;
	}
	if (const QTabWidget *tw = qobject_cast<const QTabWidget *>(parentWidget())) {
		if (tw->cornerWidget(Qt::TopLeftCorner) || tw->cornerWidget(Qt::BottomLeftCorner))
			opt.cornerWidgets |= QStyleOptionTab::LeftCornerWidget;
		if (tw->cornerWidget(Qt::TopRightCorner) || tw->cornerWidget(Qt::BottomRightCorner))
			opt.cornerWidgets |= QStyleOptionTab::RightCornerWidget;
	}
	return opt;
}
Ejemplo n.º 16
0
bool SC_SimulateTab::is_Default_New_Tab( int index )
{
    bool retval = false;
    if ( index >= 0 && index < count() &&
         !isACloseAllExclude( widget( index ) ) )
        retval = (tabText( index ) == defaultSimulateTabTitle &&
                  static_cast<SC_TextEdit*>(widget( index )) -> toPlainText() == defaultSimulateText);
    return retval;
}
Ejemplo n.º 17
0
QStringList TabWidget::tabs() const
{
    QStringList tabs;

    for( int i = 0; i < count(); ++i )
        tabs.append( tabText(i) );

    return tabs;
}
Ejemplo n.º 18
0
/*!
    \details Set if tabs text is elided or not
    \param elided True for elided text, else false
*/
void pTabBar::setTabsElided( bool elided )
{
    if ( aToggleTabsElided->isChecked() == elided && sender() != aToggleTabsElided )
        return;
    aToggleTabsElided->setChecked( elided );
    setElideMode( elided ? Qt::ElideMiddle : Qt::ElideNone );
    setTabText( 0, tabText( 0 ) ); // workaround for tabs update
    emit tabsElidedChanged( aToggleTabsElided->isChecked() );
}
Ejemplo n.º 19
0
QcrTabWidget::QcrTabWidget(const QString& _name)
    : QcrSingleValue<int> {_name, 0}
{
    doSetValue(cell_->val());
    QTabWidget::connect(this, &QTabWidget::currentChanged, [this](int val) {
            if (spuriousCall_)
                return;
            onChangedValue(val, tabText(val)); });
}
Ejemplo n.º 20
0
void 
Unicorn::TabBar::addWidget( QWidget* wi )
{
    layout()->addWidget( wi );
    int w = 0;
    for (int i = 0; i < count(); ++i)
        w = qMax( fontMetrics().width( tabText( i ) ), w );
    setMinimumWidth(  (m_leftMargin + (count() * ( w + 20 ))) + 10 + layout()->minimumSize().width());
}
Ejemplo n.º 21
0
bool PaneSubWidget::eventFilter(QObject *object, QEvent *event)
{
    // handle all events
    if (object == tabBar())
    {
        if (event->type() == QEvent::MouseButtonPress && qApp->mouseButtons() == Qt::LeftButton)
        {
            // mouse button was pressed, so keep attention
            startDragging=true;
        }
        else if (event->type() == QEvent::MouseMove)
        {
            // EVENT: move pane
            // the mouse is moving, just check wazzup
            if (!tabBar()->rect().contains(static_cast<QMouseEvent*>(event)->pos()))
            {
                // the left mouse button was pressed down --> good sign for dragging
                if(startDragging)
                {
                    // bugfixing Qt (which will activate another tab and move that in addition)
                    QMouseEvent* releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease,static_cast<QMouseEvent*>(event)->pos(),Qt::LeftButton, Qt::LeftButton, 0);
                    qApp->sendEvent(tabBar(), releaseEvent);
                    // get active widget that was clicked
                    QWidget* widget = currentWidget();

                    const int idx = indexOf(widget);
                    // just remember some information
                    CurrentWidget mCurrentWidget;
                    mCurrentWidget.Parent = qobject_cast<PaneSubWidget*>(this);
                    mCurrentWidget.Widget = widget;
                    mCurrentWidget.Index = idx;
                    mCurrentWidget.Title = tabText(idx);
                    mCurrentWidget.InDragProcess=true;
                    mCurrentWidget.LastPane = this;
                    // remove the tab
                    removeTab(idx);
                    // tell everybody the news
                    emit dragPane(mCurrentWidget);
                    // we do NOT start, we currently DO dragging
                    startDragging=false;
                    isDragging=true;
                }
            }
            if(isDragging)
                emit movePane(true);
            return false;
        }
        // EVENT: release pane
        else if (event->type() == QEvent::MouseButtonRelease)
        {
            // the user releases the mouse button
            emit releasePane();
        }
    }
    return QTabWidget::eventFilter(object, event);
}
Ejemplo n.º 22
0
void FooTabWidget::cloneTab(int index)
{
	QString newName = QString(tr("Copy of %1")).arg(tabText(index));
	//FooPlaylistWidget *fpw = qobject_cast<FooPlaylistWidget *> (widget(index));
	FooPlaylistWidget *fpwCopy = new FooPlaylistWidget ();
	addTab (fpwCopy, newName);

	connect(fpwCopy, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClicked(QModelIndex)));

}
Ejemplo n.º 23
0
int MainTabsWidget::getTabIndex(QString& name)
{
    for (int i = 0; i < count(); ++i)
    {
        if (name == tabText(i)) {
            return i;                            
        }
    }

    return -1;
}
Ejemplo n.º 24
0
void TabBar::triggerRename(int index)
{
    renamingIndex_ = index;
    lineEdit_ = new QLineEdit(this);
    lineEdit_->setText(tabText(index));
    lineEdit_->installEventFilter(this);
    lineEdit_->setGeometry(tabRect(index));
    lineEdit_->setCursorPosition(lineEdit_->text().size());
    lineEdit_->setFocus();
    lineEdit_->show();
}
Ejemplo n.º 25
0
QTextEdit *TabWidget::getTextEdit(QString title)
{
	for(int i = 0; i < count(); i++)
	{
		if(title.compare(tabText(i)) == 0)
		{
			return qobject_cast<QTextEdit *>(widget(i));
		}
	}
	return nullptr;
}
Ejemplo n.º 26
0
void PlaylistTabBar::Rename() {
  if (menu_index_ == -1) return;

  QString name = tabText(menu_index_);
  name = QInputDialog::getText(this, tr("Rename playlist"),
                               tr("Enter a new name for this playlist"),
                               QLineEdit::Normal, name);

  if (name.isNull()) return;

  emit Rename(tabData(menu_index_).toInt(), name);
}
Ejemplo n.º 27
0
/** Rename a tab. */
void TabBar::renameTab()
{
	this->setTabText(currentIndex(), lineEdit->text());
	emit tabRenamed(currentIndex(), tabText(currentIndex()));
	lineEdit->close();
	for (int t = 0; t < count(); t++) {
		QWidget *button = tabButton(t, QTabBar::RightSide);
		if (button) {
			button->setEnabled(true);
		}
	}
}
Ejemplo n.º 28
0
void MessageWindow::closeTab(Contact *contact)
{
    if (!m_pages.contains(contact))
        return;

    // find tab and close it
    for (int i = 0; i < count(); i++) {
        if (tabText(i) == contact->username()) {
            tabCloseRequested(i);
            return;
        }
    }
}
Ejemplo n.º 29
0
void TabWidget::setTabText(int tabIndex, const QString &tabName)
{
    const QString oldTabName = tabText(tabIndex);
    if ( m_tabItemCounters.contains(oldTabName) )
        m_tabItemCounters.insert( tabName, m_tabItemCounters.take(oldTabName) );

    if ( isTreeModeEnabled() )
        m_tabTree->setTabText(tabIndex, tabName);
    else
        m_tabBar->setTabText(tabIndex, tabName);

    updateSize();
}
Ejemplo n.º 30
0
bool DatabaseTabWidget::closeDatabase(Database* db)
{
    Q_ASSERT(db);

    const DatabaseManagerStruct& dbStruct = m_dbList.value(db);
    int index = databaseIndex(db);
    Q_ASSERT(index != -1);

    QString dbName = tabText(index);
    if (dbName.right(1) == "*") {
        dbName.chop(1);
    }
    if (dbStruct.dbWidget->isInEditMode() && db->hasKey() && dbStruct.dbWidget->isEditWidgetModified()) {
        QMessageBox::StandardButton result =
            MessageBox::question(
            this, tr("Close?"),
            tr("\"%1\" is in edit mode.\nDiscard changes and close anyway?").arg(dbName),
            QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
        if (result == QMessageBox::Cancel) {
            return false;
        }
    }
    if (dbStruct.modified) {
        if (config()->get("AutoSaveOnExit").toBool()) {
            if (!saveDatabase(db)) {
                return false;
            }
        }
        else {
            QMessageBox::StandardButton result =
                MessageBox::question(
                this, tr("Save changes?"),
                tr("\"%1\" was modified.\nSave changes?").arg(dbName),
                QMessageBox::Yes | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Yes);
            if (result == QMessageBox::Yes) {
                if (!saveDatabase(db)) {
                        return false;
                }
            }
            else if (result == QMessageBox::Cancel) {
                return false;
            }
        }
    }

    deleteDatabase(db);

    return true;
}