VBoxSettingsSelector.cpp revision c8db1db099a06ef2a418a24d38d233e3402c8c66
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VBoxSettingsSelector class implementation
*/
/*
* Copyright (C) 2008-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Global includes */
#include <QHeaderView>
#include <QTabWidget>
#include <QLayout>
#include <QAction>
/* Local includes */
#include "VBoxSettingsSelector.h"
#include "UISettingsPage.h"
#include "UIToolBar.h"
#include "QITreeWidget.h"
#include "QITabWidget.h"
#include "UIIconPool.h"
enum
{
/* mTwSelector column numbers */
treeWidget_Category = 0,
};
class SelectorItem
{
public:
SelectorItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, UISettingsPage* aPage, int aParentId)
{}
protected:
int mId;
int mParentId;
};
{
}
{
}
{
}
{
return text;
}
{
return page;
}
{
return list;
}
{
return list;
}
{
{
break;
}
return result;
}
{
{
break;
}
return result;
}
{
{
break;
}
return result;
}
/* VBoxSettingsTreeViewSelector */
/* Returns the path to the item in the form of 'grandparent > parent > item'
* using the text of the first column of every item. */
{
QString p;
while (cur)
{
if (!p.isNull())
p = sep + p;
}
return p;
}
{
/* Configure the selector */
mTwSelector->setRootIsDecorated (false);
mTwSelector->setUniformRowHeights (true);
/* Add the columns */
/* Hide unnecessary columns and header */
/* Setup connections */
}
{
return mTwSelector;
}
const QString &strMediumIcon ,
const QString & /* strSmallIcon */,
int aId,
int aParentId /* = -1 */)
{
{
<< idToString (aId)
<< aLink);
aPage->setContentsMargins (0, 0, 0, 0);
}
return result;
}
{
if (item)
}
{
}
int VBoxSettingsTreeViewSelector::currentId () const
{
int id = -1;
if (item)
return id;
}
{
int id = -1;
if (item)
return id;
}
{
if (item)
}
{
if (item)
}
void VBoxSettingsTreeViewSelector::polish()
{
/* Get recommended size hint: */
int iItemWidth = static_cast<QAbstractItemView*>(mTwSelector)->sizeHintForColumn(treeWidget_Category);
int iItemHeight = qMax(24 /* icon height */, mTwSelector->fontMetrics().height() /* text height */);
/* Add some margin to every item in the tree: */
/* Set final size hint for items: */
/* Fix selector width to minimum possible: */
/* Sort selector by the id column: */
/* Resize column(s) to content: */
}
QTreeWidgetItem * /* aPrevItem */)
{
if (aItem)
{
}
}
void VBoxSettingsTreeViewSelector::clear()
{
mTwSelector->clear();
}
/**
* Returns a path to the given page of this settings window. See ::path() for
* details.
*/
{
}
/* Returns first item of 'aView' matching required 'aMatch' value
* searching the 'aColumn' column. */
int aColumn) const
{
}
{
}
/* VBoxSettingsToolBarSelector */
class SelectorActionItem: public SelectorItem
{
public:
SelectorActionItem (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, UISettingsPage* aPage, int aParentId, QObject *aParent)
, mTabWidget (NULL)
{
mAction->setCheckable (true);
}
protected:
};
{
/* Init the toolbar */
mTbSelector->setUsesTextLabel (true);
#ifdef Q_WS_MAC
mTbSelector->setShowToolBarButton (false);
#endif /* Q_WS_MAC */
/* Init the action group for house keeping */
mActionGroup = new QActionGroup (this);
mActionGroup->setExclusive (true);
}
{
delete mTbSelector;
}
{
return mTbSelector;
}
const QString & /* strMediumIcon */,
const QString &strSmallIcon,
int aId,
int aParentId /* = -1 */)
{
if (aParentId == -1 &&
{
aPage->setContentsMargins (0, 0, 0, 0);
}
else if (aParentId == -1 &&
{
tabWidget->setContentsMargins (0, 0, 0, 0);
// connect (tabWidget, SIGNAL (currentChanged (int)),
// this, SLOT (settingsGroupChanged (int)));
}
else
{
if (parent)
{
if (tabWidget)
}
}
return result;
}
{
{
{
if (parent &&
}
}
}
{
return result;
}
int VBoxSettingsToolBarSelector::currentId () const
{
int id = -1;
if (action)
return id;
}
{
int id = -1;
if (item)
return id;
}
{
{
if (!page)
}
return page;
}
{
{
else
}
return page;
}
{
{
{
if (parent &&
{
}
}
else
}
}
{
if (item)
{
{
if (parent &&
{
if (aShow &&
else if (!aShow &&
}
}
}
}
void VBoxSettingsToolBarSelector::clear()
{
delete action;
}
int VBoxSettingsToolBarSelector::minWidth() const
{
}
{
if (item)
{
// if (item->page() &&
// !item->tabWidget())
// emit categoryChanged (item->id());
// else
// {
//
// item->tabWidget()->blockSignals (true);
// item->tabWidget()->setCurrentIndex (0);
// item->tabWidget()->blockSignals (false);
// printf ("%s\n", qPrintable(item->text()));
// SelectorActionItem *child = static_cast<SelectorActionItem*> (
// findItemByPage (static_cast<UISettingsPage*> (item->tabWidget()->currentWidget())));
// if (child)
// emit categoryChanged (child->id());
// }
}
}
{
SelectorActionItem *item = findActionItemByTabWidget (qobject_cast<QTabWidget*> (sender()), aIndex);
if (item)
{
else
{
if (child)
}
}
}
{
}
SelectorActionItem *VBoxSettingsToolBarSelector::findActionItemByTabWidget (QTabWidget* aTabWidget, int aIndex) const
{
{
result = static_cast<SelectorActionItem*> (
break;
}
return result;
}
{
{
}
return list;
}
{
{
break;
}
return result;
}