Exemplo n.º 1
0
bool Panel::onTabClose( TabPtr tab )
{
	bool doClose = false;

	int cnt = Manager::instance().dock()->getContentCount( tab->getContent()->getContentID() );
	ASSERT( cnt != 0 );

	Content::OnCloseAction response = tab->getContent()->onClose( (cnt == 1) );
	if ( response == Content::CONTENT_KEEP )
	{
		doClose = false;
	}
	else if ( response == Content::CONTENT_HIDE )
	{
		showTab( tab, false );
		doClose = true;
	}
	else if ( response == Content::CONTENT_DESTROY )
	{
		detachTab( tab );
		doClose = true;
	}
	else
		ASSERT( 0 );

	return doClose;
}
Exemplo n.º 2
0
TabPtr Panel::detachFirstTab()
{
	if ( tabList_.empty() )
		return 0;

	TabPtr tab = *(tabList_.begin());

	detachTab( *(tabList_.begin()) );

	return tab;
}
Exemplo n.º 3
0
void Panel::detachTab( const std::string contentID )
{
	for(TabItr i = tabList_.begin(); i != tabList_.end(); )
	{
		if ( contentID.compare( (*i)->getContent()->getContentID() ) == 0 )
		{
			// restart iterator since detachTab will remove the tab from the list
			TabItr old = i;
			++i;
			detachTab( *old );
		}
		else
			++i;
	}
}
Exemplo n.º 4
0
void TabBarWidget::contextMenuEvent(QContextMenuEvent *event)
{
	m_clickedTab = tabAt(event->pos());

	hidePreview();

	QMenu menu(this);
	menu.addAction(ActionsManager::getAction(QLatin1String("NewTab"), this));
	menu.addAction(ActionsManager::getAction(QLatin1String("NewTabPrivate"), this));

	if (m_clickedTab >= 0)
	{
		const bool isPinned = getTabProperty(m_clickedTab, QLatin1String("isPinned"), false).toBool();

		menu.addAction(tr("Clone Tab"), this, SLOT(cloneTab()))->setEnabled(getTabProperty(m_clickedTab, QLatin1String("canClone"), false).toBool());
		menu.addAction((isPinned ? tr("Unpin Tab") : tr("Pin Tab")), this, SLOT(pinTab()));
		menu.addSeparator();
		menu.addAction(tr("Detach Tab"), this, SLOT(detachTab()))->setEnabled(count() > 1);
		menu.addSeparator();

		if (isPinned)
		{
			QAction *closeAction = menu.addAction(Utils::getIcon(QLatin1String("tab-close")), tr("Close Tab"));

			ActionsManager::setupLocalAction(ActionsManager::getAction(QLatin1String("CloseTab"), this), closeAction, true);

			closeAction->setEnabled(false);
		}
		else
		{
			menu.addAction(ActionsManager::getAction(QLatin1String("CloseTab"), this));
		}

		const int amount = (count() - getPinnedTabsAmount());

		menu.addAction(Utils::getIcon(QLatin1String("tab-close-other")), tr("Close Other Tabs"), this, SLOT(closeOther()))->setEnabled(amount > 0 && !(amount == 1 && !isPinned));
	}

	menu.exec(event->globalPos());

	m_clickedTab = -1;

	if (underMouse())
	{
		m_previewTimer = startTimer(250);
	}
}
Exemplo n.º 5
0
KrViewer::KrViewer(QWidget *parent) :
        KParts::MainWindow(parent, (Qt::WindowFlags)KDE_DEFAULT_WINDOWFLAGS), manager(this, this), tabBar(this),
        reservedKeys(), reservedKeyActions(), sizeX(-1), sizeY(-1)
{
    //setWFlags(Qt::WType_TopLevel | WDestructiveClose);
    setXMLFile("krviewer.rc");   // kpart-related xml file
    setHelpMenuEnabled(false);

    connect(&manager, SIGNAL(activePartChanged(KParts::Part*)),
            this, SLOT(createGUI(KParts::Part*)));
    connect(&tabBar, &QTabWidget::currentChanged, this, &KrViewer::tabChanged);
    connect(&tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequest(int)));

    tabBar.setDocumentMode(true);
    tabBar.setMovable(true);
    setCentralWidget(&tabBar);

    printAction = KStandardAction::print(this, SLOT(print()), 0);
    copyAction = KStandardAction::copy(this, SLOT(copy()), 0);

    viewerMenu = new QMenu(this);
    QAction *tempAction;
    KActionCollection *ac = actionCollection();

#define addCustomMenuAction(name, text, slot, shortcut)\
    tempAction = ac->addAction(name, this, slot);\
    tempAction->setText(text);\
    ac->setDefaultShortcut(tempAction, shortcut);\
    viewerMenu->addAction(tempAction);

    addCustomMenuAction("genericViewer", i18n("&Generic Viewer"), SLOT(viewGeneric()), Qt::CTRL + Qt::SHIFT + Qt::Key_G);
    addCustomMenuAction("textViewer", i18n("&Text Viewer"), SLOT(viewText()), Qt::CTRL + Qt::SHIFT + Qt::Key_T);
    addCustomMenuAction("hexViewer", i18n("&Hex Viewer"), SLOT(viewHex()), Qt::CTRL + Qt::SHIFT + Qt::Key_H);
    addCustomMenuAction("lister", i18n("&Lister"), SLOT(viewLister()), Qt::CTRL + Qt::SHIFT + Qt::Key_L);
    viewerMenu->addSeparator();

    addCustomMenuAction("textEditor", i18n("Text &Editor"), SLOT(editText()), Qt::CTRL + Qt::SHIFT + Qt::Key_E);
    viewerMenu->addSeparator();

    QList<QAction *> actList = menuBar()->actions();
    bool hasPrint = false, hasCopy = false;
    foreach(QAction *a, actList) {
        if (a->shortcut().matches(printAction->shortcut()) != QKeySequence::NoMatch)
            hasPrint = true;
        if (a->shortcut().matches(copyAction->shortcut()) != QKeySequence::NoMatch)
            hasCopy = true;
    }
    QAction *printAct = viewerMenu->addAction(printAction->icon(), printAction->text(), this, SLOT(print()));
    if (hasPrint)
        printAct->setShortcut(printAction->shortcut());
    QAction *copyAct = viewerMenu->addAction(copyAction->icon(), copyAction->text(), this, SLOT(copy()));
    if (hasCopy)
        copyAct->setShortcut(copyAction->shortcut());
    viewerMenu->addSeparator();

    configKeysAction = ac->addAction(KStandardAction::KeyBindings, this, SLOT(configureShortcuts()));
    viewerMenu->addAction(configKeysAction);
    viewerMenu->addSeparator();

    detachAction = ac->addAction("detachTab", this, SLOT(detachTab()));
    detachAction->setText(i18n("&Detach Tab"));
    //no point in detaching only one tab..
    detachAction->setEnabled(false);
    ac->setDefaultShortcut(detachAction, Qt::META + Qt::Key_D);
    viewerMenu->addAction(detachAction);

    quitAction = ac->addAction(KStandardAction::Quit, this, SLOT(close()));
    viewerMenu->addAction(quitAction);

    tabCloseAction = ac->addAction("closeTab", this, SLOT(tabCloseRequest()));
    tabCloseAction->setText(i18n("&Close Current Tab"));
    QList<QKeySequence> shortcuts = KStandardShortcut::close();
    shortcuts.append(Qt::Key_Escape);
    ac->setDefaultShortcuts(tabCloseAction, shortcuts);

    tabNextAction = ac->addAction("nextTab", this, SLOT(nextTab()));
    tabNextAction->setText(i18n("&Next Tab"));
    ac->setDefaultShortcuts(tabNextAction, KStandardShortcut::tabNext());

    tabPrevAction = ac->addAction("prevTab", this, SLOT(prevTab()));
    tabPrevAction->setText(i18n("&Previous Tab"));
    ac->setDefaultShortcuts(tabPrevAction, KStandardShortcut::tabPrev());


    tabBar.setTabsClosable(true);

    checkModified();

    KConfigGroup group(krConfig, "KrViewerWindow");
    int sx = group.readEntry("Window Width", -1);
    int sy = group.readEntry("Window Height", -1);

    if (sx != -1 && sy != -1)
        resize(sx, sy);
    else
        resize(900, 700);

    if (group.readEntry("Window Maximized",  false)) {
        setWindowState(windowState() | Qt::WindowMaximized);
    }

    // filtering out the key events
    menuBar() ->installEventFilter(this);
}
Exemplo n.º 6
0
void TabBar::detachTab()
{
    emit detachTab(m_actualIndex);
    m_actualIndex = -1;
}
Exemplo n.º 7
0
void TabBarWidget::contextMenuEvent(QContextMenuEvent *event)
{
	m_clickedTab = tabAt(event->pos());

	if (m_previewWidget && m_previewWidget->isVisible())
	{
		m_previewWidget->hide();
	}

	if (m_previewTimer > 0)
	{
		killTimer(m_previewTimer);

		m_previewTimer = 0;
	}

	QMenu menu(this);
	menu.addAction(ActionsManager::getAction(QLatin1String("NewTab")));
	menu.addAction(ActionsManager::getAction(QLatin1String("NewTabPrivate")));

	if (m_clickedTab >= 0)
	{
		const bool isPinned = getTabProperty(m_clickedTab, QLatin1String("isPinned"), false).toBool();
		int amount = 0;

		for (int i = 0; i < count(); ++i)
		{
			if (getTabProperty(i, QLatin1String("isPinned"), false).toBool() || i == m_clickedTab)
			{
				continue;
			}

			++amount;
		}

		menu.addAction(tr("Clone Tab"), this, SLOT(cloneTab()))->setEnabled(getTabProperty(m_clickedTab, QLatin1String("canClone"), false).toBool());
		menu.addAction((isPinned ? tr("Unpin Tab") : tr("Pin Tab")), this, SLOT(pinTab()));
		menu.addSeparator();
		menu.addAction(tr("Detach Tab"), this, SLOT(detachTab()))->setEnabled(count() > 1);
		menu.addSeparator();

		if (isPinned)
		{
			QAction *closeAction = menu.addAction(QString());

			ActionsManager::setupLocalAction(closeAction, QLatin1String("CloseTab"), true);

			closeAction->setEnabled(false);
		}
		else
		{
			menu.addAction(ActionsManager::getAction(QLatin1String("CloseTab")));
		}

		menu.addAction(QIcon(":/icons/tab-close-other.png"), tr("Close Other Tabs"), this, SLOT(closeOther()))->setEnabled(amount > 0);
	}

	menu.exec(event->globalPos());

	m_clickedTab = -1;

	if (underMouse())
	{
		m_previewTimer = startTimer(250);
	}
}
Exemplo n.º 8
0
void TabBarWidget::contextMenuEvent(QContextMenuEvent *event)
{
	m_clickedTab = tabAt(event->pos());

	hidePreview();

	QMenu menu(this);
	menu.addAction(ActionsManager::getAction(ActionsManager::NewTabAction, this));
	menu.addAction(ActionsManager::getAction(ActionsManager::NewTabPrivateAction, this));

	if (m_clickedTab >= 0)
	{
		const bool isPinned = getTabProperty(m_clickedTab, QLatin1String("isPinned"), false).toBool();
		Action *cloneTabAction = new Action(ActionsManager::CloneTabAction, &menu);
		cloneTabAction->setEnabled(getTabProperty(m_clickedTab, QLatin1String("canClone"), false).toBool());

		Action *pinTabAction = new Action(ActionsManager::PinTabAction, &menu);
		pinTabAction->setOverrideText(isPinned ? QT_TRANSLATE_NOOP("actions", "Unpin Tab") : QT_TRANSLATE_NOOP("actions", "Pin Tab"));

		Action *detachTabAction = new Action(ActionsManager::DetachTabAction, &menu);
		detachTabAction->setEnabled(count() > 1);

		menu.addAction(cloneTabAction);
		menu.addAction(pinTabAction);
		menu.addSeparator();
		menu.addAction(detachTabAction);
		menu.addSeparator();

		if (isPinned)
		{
			Action *closeTabAction = new Action(ActionsManager::CloseTabAction, &menu);
			closeTabAction->setEnabled(false);

			menu.addAction(closeTabAction);
		}
		else
		{
			menu.addAction(ActionsManager::getAction(ActionsManager::CloseTabAction, this));
		}

		const int amount = (count() - getPinnedTabsAmount());
		Action *closeOtherTabsAction = new Action(ActionsManager::CloseOtherTabsAction, &menu);
		closeOtherTabsAction->setEnabled(amount > 0 && !(amount == 1 && !isPinned));

		menu.addAction(closeOtherTabsAction);
		menu.addAction(ActionsManager::getAction(ActionsManager::ClosePrivateTabsAction, this));

		connect(cloneTabAction, SIGNAL(triggered()), this, SLOT(cloneTab()));
		connect(pinTabAction, SIGNAL(triggered()), this, SLOT(pinTab()));
		connect(detachTabAction, SIGNAL(triggered()), this, SLOT(detachTab()));
		connect(closeOtherTabsAction, SIGNAL(triggered()), this, SLOT(closeOtherTabs()));
	}

	menu.addSeparator();

	QMenu *arrangeMenu = menu.addMenu(tr("Arrange"));
	arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::RestoreTabAction, this));
	arrangeMenu->addSeparator();
	arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::RestoreAllAction, this));
	arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::MaximizeAllAction, this));
	arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::MinimizeAllAction, this));
	arrangeMenu->addSeparator();
	arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::CascadeAllAction, this));
	arrangeMenu->addAction(ActionsManager::getAction(ActionsManager::TileAllAction, this));

	QAction *cycleAction = new QAction(tr("Switch tabs using the mouse wheel"), this);
	cycleAction->setCheckable(true);
	cycleAction->setChecked(!SettingsManager::getValue(QLatin1String("TabBar/RequireModifierToSwitchTabOnScroll")).toBool());

	connect(cycleAction, SIGNAL(toggled(bool)), this, SLOT(setCycle(bool)));

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

	if (toolBar)
	{
		QList<QAction*> actions;
		actions.append(cycleAction);

		menu.addMenu(ToolBarWidget::createCustomizationMenu(ToolBarsManager::TabBar, actions, &menu));
	}
	else
	{
		QMenu *customizationMenu = menu.addMenu(tr("Customize"));
		customizationMenu->addAction(cycleAction);
		customizationMenu->addSeparator();
		customizationMenu->addAction(ActionsManager::getAction(ActionsManager::LockToolBarsAction, this));
	}

	menu.exec(event->globalPos());

	cycleAction->deleteLater();

	m_clickedTab = -1;

	if (underMouse())
	{
		m_previewTimer = startTimer(250);
	}
}
Exemplo n.º 9
0
void TabBar::contextMenuEvent(QContextMenuEvent* event)
{
    int index = tabAt(event->pos());
    m_clickedTab = index;

    QMenu menu;
    menu.addAction(IconProvider::newTabIcon(), tr("&New tab"), m_window, SLOT(addTab()));
    menu.addSeparator();
    if (index != -1) {
        WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
        if (!webTab) {
            return;
        }

        if (m_window->weView(m_clickedTab)->isLoading()) {
            menu.addAction(QIcon::fromTheme(QSL("process-stop")), tr("&Stop Tab"), this, SLOT(stopTab()));
        }
        else {
            menu.addAction(QIcon::fromTheme(QSL("view-refresh")), tr("&Reload Tab"), this, SLOT(reloadTab()));
        }

        menu.addAction(QIcon::fromTheme("tab-duplicate"), tr("&Duplicate Tab"), this, SLOT(duplicateTab()));

        if (count() > 1 && !webTab->isPinned()) {
            menu.addAction(QIcon::fromTheme("tab-detach"), tr("D&etach Tab"), this, SLOT(detachTab()));
        }

        menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
        menu.addSeparator();
        menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
        menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
        menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
        menu.addSeparator();
        menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
        menu.addSeparator();
        menu.addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent()));
        menu.addAction(QIcon::fromTheme("window-close"), tr("Cl&ose"), this, SLOT(closeTab()));
        menu.addSeparator();
    }
    else {
        menu.addAction(tr("Reloa&d All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
        menu.addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs()));
        menu.addSeparator();
        menu.addAction(m_window->action(QSL("Other/RestoreClosedTab")));
    }

    m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(m_tabWidget->canRestoreTab());

    // Prevent choosing first option with double rightclick
    const QPoint pos = event->globalPos();
    QPoint p(pos.x(), pos.y() + 1);
    menu.exec(p);

    m_window->action(QSL("Other/RestoreClosedTab"))->setEnabled(true);
}