[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/nepomuk-kde/annotation/lib/gui
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2010-05-18 15:12:34
Message-ID: 20100518151234.08A2FAC8B9 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1128176 by trueg:
Added config option to show sub menus to shrink the main menu
M +85 -33 annotationmenu.cpp
M +2 -1 annotationmenu.h
--- trunk/playground/base/nepomuk-kde/annotation/lib/gui/annotationmenu.cpp \
#1128175:1128176 @@ -146,7 +146,7 @@
void addContextActions( KMenu* menu );
void addAnnotationActions( KMenu* menu );
void addTagActions( KMenu* menu );
- void addSearchAction();
+ void addSearchAction( KMenu* menu );
void _k_menuAboutToShow();
void _k_ratingChanged(unsigned int);
@@ -178,6 +178,10 @@
QPointer<QAction> m_tagBusyAction;
bool m_annotationTitleCreated;
+ QPointer<QMenu> m_tagActionMenu;
+ QPointer<QMenu> m_relateToActionMenu;
+ QPointer<QMenu> m_contextActionMenu;
+
int m_tagActionCount;
SearchMenu* m_searchMenu;
@@ -266,7 +270,7 @@
{
kDebug() << resource;
Nepomuk::Resource res( resource );
- QAction* action = new QAction( q );
+ QAction* action = new QAction( m_relateToActionMenu );
q->setElidedActionText( action, res.genericLabel(), Types::Class( \
res.resourceType() ).label() ); action->setData( QVariant::fromValue( res ) );
q->connect( action, SIGNAL( triggered() ), SLOT( _k_relateToActionTriggered() ) \
); @@ -278,7 +282,7 @@
{
kDebug() << resource;
Nepomuk::Resource res( resource );
- QAction* action = new QAction( q );
+ QAction* action = new QAction( m_contextActionMenu );
q->setElidedActionText( action, res.genericLabel(), Types::Class( \
res.resourceType() ).label() ); action->setData( QVariant::fromValue( res ) );
q->connect( action, SIGNAL( triggered() ), SLOT( _k_contextActionTriggered() ) \
); @@ -310,7 +314,7 @@
QAction* Nepomuk::AnnotationMenu::Private::createTagAction( const Nepomuk::Tag& tag \
) const {
kDebug() << tag;
- QAction* action = new QAction( q );
+ QAction* action = new QAction( m_tagActionMenu );
action->setCheckable(true);
q->setElidedActionText( action, tag.genericLabel() );
action->setData( QVariant::fromValue( tag ) );
@@ -325,7 +329,7 @@
QAction* Nepomuk::AnnotationMenu::Private::createShowAllTagsAction() const
{
kDebug();
- QAction* action = new QAction( q );
+ QAction* action = new QAction( m_tagActionMenu );
action->setText( i18nc( "@action:inmenu", "Show all tags..." ) );
q->connect( action, SIGNAL( triggered() ), SLOT( _k_showAllTags() ) );
return action;
@@ -382,8 +386,11 @@
void Nepomuk::AnnotationMenu::Private::addRelateToActions( KMenu* menu )
{
kDebug();
+
+ m_relateToActionMenu = menu;
+
// add widget action showing a busy thingi and query the resources async
- m_relateToBusyAction = q->createBusyAction(q);
+ m_relateToBusyAction = q->createBusyAction(menu);
menu->addAction( m_relateToBusyAction );
// query: select the resources that are not already related to m_resource
@@ -433,9 +440,11 @@
{
kDebug();
+ m_contextActionMenu = menu;
+
// add widget action showing a busy thingi and query the resources async
- m_contextQueryBusyAction = q->createBusyAction(q);
- menu->addAction( m_contextQueryBusyAction );
+ m_contextQueryBusyAction = q->createBusyAction(menu);
+ m_contextActionMenu->addAction( m_contextQueryBusyAction );
// query resources of the supported types that have a high usage count
Query::AndTerm mainTerm;
@@ -474,7 +483,7 @@
kDebug();
if ( m_resources.count() == 1 ) {
// add widget action showing a busy thingi and query the resources async
- m_annotationsBusyAction = q->createBusyAction(q);
+ m_annotationsBusyAction = q->createBusyAction(menu);
menu->addAction( m_annotationsBusyAction );
m_annotationTitleCreated = false;
@@ -496,10 +505,12 @@
{
kDebug();
+ m_tagActionMenu = menu;
+
m_tagActionCount = 0;
// add widget action showing a busy thingi and query the resources async
- m_tagBusyAction = q->createBusyAction(q);
+ m_tagBusyAction = q->createBusyAction(menu);
menu->addAction( m_tagBusyAction );
// query most used tags
@@ -535,16 +546,16 @@
}
-void Nepomuk::AnnotationMenu::Private::addSearchAction()
+void Nepomuk::AnnotationMenu::Private::addSearchAction( KMenu* menu )
{
kDebug();
if ( !m_searchMenu ) {
- m_searchMenu = new SearchMenu( q );
+ m_searchMenu = new SearchMenu( menu );
m_searchMenu->setSearchWhileYouTypeEnabled( true );
q->connect( m_searchMenu, SIGNAL( resultTriggered( Nepomuk::Query::Result ) \
),
SLOT( _k_searchResultTriggered( Nepomuk::Query::Result ) ) );
}
- QAction* action = q->addMenu( m_searchMenu );
+ QAction* action = menu->addMenu( m_searchMenu );
action->setText( i18nc( "@action:inmenu", "Search..." ) );
}
@@ -554,47 +565,87 @@
if ( !m_menuCreated ) {
m_menuCreated = true;
+ KMenu* relateMenu = q;
+
if ( !m_resources.isEmpty() ) {
if ( m_resources.count() == 1 )
q->addTitle( KIcon( "nepomuk" ), i18nc( "@title menu title", \
"Annotate %1", m_resources.first().genericLabel() ) ); else
q->addTitle( KIcon( "nepomuk" ), i18nc( "@title menu title", \
"Annotate resource" ) );
- if ( m_configFlags & AnnotationMenu::ShowRatingAction )
+ if ( m_configFlags & AnnotationMenu::ShowRatingAction ) {
addRatingAction( q );
+ if ( m_configFlags & AnnotationMenu::UseSubMenus ) {
+ q->addSeparator();
+ }
+ }
if ( m_configFlags & AnnotationMenu::ShowTagActions ) {
- q->addTitle( i18nc( "@title:menu title above a set of tags that can \
be applied to the current resource.",
- "Tag with:" ) );
+ const QString title = i18nc( "@title:menu title above a set of tags \
that can be applied to the current resource.", + \
"Tag with" ); + if ( m_configFlags & AnnotationMenu::UseSubMenus ) {
+ KMenu* subMenu = new KMenu( title, q );
+ q->addMenu( subMenu );
+ addTagActions( subMenu );
+ }
+ else {
+ q->addTitle( title + ':' );
addTagActions( q );
}
+ }
- if ( m_configFlags & AnnotationMenu::ShowRelatedResourcesActions ) {
- q->addTitle( i18nc( "@title:menu title above a set of resources that \
can be marked as related to the current resource.",
- "Relate to:" ) );
- addRelateToActions( q );
+ if ( m_configFlags & ( \
AnnotationMenu::ShowRelatedResourcesActions|AnnotationMenu::ShowSearchAction|AnnotationMenu::ShowNewResourceActions \
) ) { + const QString relateToTitle = i18nc( "@title:menu title above \
a set of resources that can be marked as related to the current resource.", + \
"Relate to" ); + if ( m_configFlags & AnnotationMenu::UseSubMenus ) {
+ relateMenu = new KMenu( relateToTitle, q );
+ q->addMenu( relateMenu );
}
+ else {
+ q->addTitle( relateToTitle + ':' );
}
+ }
+ }
else {
q->addTitle( i18nc( "@title:menu title above a set of resources that can \
be set as the current working context.", "Work in Context of:" ) );
- addContextActions( q );
}
- if ( m_configFlags & AnnotationMenu::ShowNewResourceActions ) {
- q->addSeparator();
- addNewResourceActions( q );
- }
-
if ( m_configFlags & AnnotationMenu::ShowSearchAction ) {
- q->addSeparator();
- addSearchAction();
+ addSearchAction( relateMenu );
if ( m_resources.isEmpty() )
m_searchMenu->setCoreQueryTerm( createResourceTypeTerm() );
else
m_searchMenu->setCoreQueryTerm( Query::Term() );
+ relateMenu->addSeparator();
}
+ if ( !m_resources.isEmpty() ) {
+ if ( m_configFlags & AnnotationMenu::ShowRelatedResourcesActions ) {
+ if ( m_configFlags & AnnotationMenu::UseSubMenus ) {
+ addRelateToActions( relateMenu );
+ }
+ else {
+ addRelateToActions( q );
+ }
+ }
+ }
+ else {
+ if ( m_configFlags & AnnotationMenu::UseSubMenus ) {
+ KMenu* subMenu = new KMenu( i18n( "Previously used" ), q );
+ q->addMenu( subMenu );
+ addContextActions( subMenu );
+ }
+ else {
+ addContextActions( q );
+ }
+ }
+
+ if ( m_configFlags & AnnotationMenu::ShowNewResourceActions ) {
+ relateMenu->addSeparator();
+ addNewResourceActions( relateMenu );
+ }
+
if ( m_configFlags & AnnotationMenu::ShowAnnotationActions &&
!m_resources.isEmpty() ) {
// a header will only be added in case that we actually find some \
possible annotations @@ -691,7 +742,7 @@
{
kDebug();
// HACK: workaround for a Virtuoso bug where URIs are returned as strings if the \
query contains an aggregate function
- q->insertAction( m_relateToBusyAction, createRelateToAction( QUrl( \
query->binding( 0 ).toString() ) ) ); + m_relateToActionMenu->insertAction( \
m_relateToBusyAction, createRelateToAction( QUrl( query->binding( 0 ).toString() ) ) \
);
// TODO: if we have more than s_maxActionsPerSection results, ignore the last \
result and add a "more..." action query->next();
}
@@ -708,7 +759,7 @@
{
kDebug();
// HACK: workaround for a Virtuoso bug where URIs are returned as strings if the \
query contains an aggregate function
- q->insertAction( m_contextQueryBusyAction, createContextAction( QUrl( \
query->binding( 0 ).toString() ) ) ); + m_contextActionMenu->insertAction( \
m_contextQueryBusyAction, createContextAction( QUrl( query->binding( 0 ).toString() ) \
) );
// TODO: if we have more than s_maxActionsPerSection results, ignore the last \
result and add a "more..." action query->next();
}
@@ -724,10 +775,10 @@
void Nepomuk::AnnotationMenu::Private::_k_nextTagReady( Soprano::Util::AsyncQuery* \
query ) {
// HACK: workaround for a Virtuoso bug where URIs are returned as strings if the \
query contains an aggregate function
- q->insertAction( m_tagBusyAction, createTagAction( QUrl( query->binding( 0 \
).toString() ) ) ); + m_tagActionMenu->insertAction( m_tagBusyAction, \
createTagAction( QUrl( query->binding( 0 ).toString() ) ) ); if ( ++m_tagActionCount \
> s_maxActionsPerSection ) { // add the "more..." action
- q->insertAction( m_tagBusyAction, createShowAllTagsAction() );
+ m_tagActionMenu->insertAction( m_tagBusyAction, createShowAllTagsAction() );
// we do not need the query anymore
query->close();
@@ -749,7 +800,8 @@
{
kDebug();
- if ( !m_annotationTitleCreated ) {
+ if ( !( m_configFlags & AnnotationMenu::UseSubMenus ) &&
+ !m_annotationTitleCreated ) {
m_annotationTitleCreated = true;
q->addTitle( i18nc( "@title:menu title above a set of possible annotations \
for the current resource.", "Annotate:" ),
--- trunk/playground/base/nepomuk-kde/annotation/lib/gui/annotationmenu.h \
#1128175:1128176 @@ -71,7 +71,8 @@
ShowAnnotationActions = 0x8,
ShowNewResourceActions = 0x10,
ShowSearchAction = 0x20,
- ShowAll = 0xFFFF
+ ShowAll = \
ShowRatingAction|ShowTagActions|ShowRelatedResourcesActions|ShowAnnotationActions|ShowNewResourceActions|ShowSearchAction,
+ UseSubMenus = 0x40
};
Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic