Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libHeaven/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SET( SRC_FILES
CentralUI/Views/View.cpp
CentralUI/Views/AbstractViewWidget.cpp
CentralUI/Views/ViewDescriptor.cpp
CentralUI/Views/ViewDescriptorRegistrar.cpp
CentralUI/Views/ViewIdentifier.cpp

CentralUI/Contexts/ContextKeys.cpp
Expand Down Expand Up @@ -202,6 +203,8 @@ SET( PRI_HDR_FILES
CentralUI/States/WindowStateView.hpp
CentralUI/States/WindowStateWindow.hpp

CentralUI/Views/ViewDescriptorRegistrar.hpp

Widgets/FooterWidget.hpp
Widgets/ModeSwitchCombo.hpp
Widgets/TabWidget.hpp
Expand All @@ -217,6 +220,7 @@ SET( RCC_FILES
)

SET( HID_FILES
CentralUI/Views/ViewsMergerActions.hid
CentralUI/ContainerWidgets/MultiBarContainerWidgetActions.hid
MultiBar/MultiBarViewWidgetActions.hid
)
Expand Down
3 changes: 3 additions & 0 deletions src/libHeaven/CentralUI/Views/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QVBoxLayout>

#include "libHeaven/CentralUI/Views/View.hpp"
#include "libHeaven/CentralUI/Views/ViewDescriptorRegistrar.hpp"
#include "libHeaven/CentralUI/Contexts/ViewContextManager.hpp"

namespace Heaven
Expand Down Expand Up @@ -152,6 +153,8 @@ namespace Heaven
*/
void View::closeView()
{
ViewDescriptor::Registrar::self().viewClosed(this);

parentContainer()->take( this );

deleteLater();
Expand Down
89 changes: 80 additions & 9 deletions src/libHeaven/CentralUI/Views/ViewDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2012-2013 The MacGitver-Developers <dev@macgitver.org>
*
* (C) Sascha Cunz <sascha@macgitver.org>
* (C) Cunz RaD Ltd
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
Expand All @@ -16,7 +17,12 @@
*
*/

#include <QDebug>
#include <QAction>

#include "libHeaven/CentralUI/Views/View.hpp"
#include "libHeaven/CentralUI/Views/ViewDescriptor.hpp"
#include "libHeaven/CentralUI/Views/ViewDescriptorRegistrar.hpp"

namespace Heaven
{
Expand All @@ -26,7 +32,7 @@ namespace Heaven
* @ingroup CentralUI
* @brief A descriptor for available views
*
* This class stores meta data about the available views. It alos acts as a factory to create
* This class stores meta data about the available views. It also acts as a factory to create
* real View objects, when required.
*
* Each instance of this class represents one View.
Expand All @@ -51,14 +57,19 @@ namespace Heaven
*/
ViewDescriptor::ViewDescriptor( const ViewIdentifier& id, const QString& displayName,
ViewDescriptor::CreatorFunc creator )
: mIdentifier( id )
, mDisplayName( displayName )
, mCreatorFunc( creator )
: mIdentifier(id)
, mDisplayName(displayName)
, mCreatorFunc(creator)
, mCreatedView(NULL)
, mActivatorAction(NULL)
{
mDescriptors.insert( id, this );
Registrar::self().insert( id, this );
}

QHash< ViewIdentifier, ViewDescriptor* > ViewDescriptor::mDescriptors;
ViewDescriptor::~ViewDescriptor()
{
delete mActivatorAction;
}

/**
* @brief Get the display name for this descriptor
Expand Down Expand Up @@ -99,7 +110,7 @@ namespace Heaven
*/
void ViewDescriptor::unregister()
{
mDescriptors.remove( mIdentifier );
Registrar::self().remove(mIdentifier);
delete this;
}

Expand All @@ -113,7 +124,7 @@ namespace Heaven
*/
ViewDescriptor* ViewDescriptor::get( const ViewIdentifier& id )
{
return mDescriptors.value( id, NULL );
return Registrar::self().get(id);
}

/**
Expand All @@ -126,8 +137,68 @@ namespace Heaven
*/
View* ViewDescriptor::createView() const
{
return mCreatorFunc();
View* view = mCreatorFunc();
if (!view) {
return NULL;
}

mCreatedView = view;

Registrar::self().viewOpened(view);

return view;
}

/**
* @brief Get the activator action of this view
*
* @return A QAction that can be used to open/close this view
*/
QAction* ViewDescriptor::activatorAction()
{
if (!mActivatorAction) {
createActivatorAction();
}

return mActivatorAction;
}

DynamicActionMerger* ViewDescriptor::actionMerger()
{
return Registrar::self().actionMerger();
}

void ViewDescriptor::createActivatorAction()
{
if (mActivatorAction) {
return;
}

mActivatorAction = new QAction(mDisplayName, &Registrar::self());
mActivatorAction->setCheckable(true);

connect(mActivatorAction, SIGNAL(triggered(bool)),
this, SLOT(onActivatorAction(bool)));
}

void ViewDescriptor::mergeViewsMenu(const QByteArray& mergePlace)
{
ViewDescriptor::Registrar::self().acViewsMergerAC->mergeInto(mergePlace);
}

void ViewDescriptor::onActivatorAction(bool triggered)
{
if (triggered && !mCreatedView) {
qDebug() << "Should open:" << mIdentifier;
}
else if (!triggered && mCreatedView) {
mCreatedView->closeView();
}
}

void ViewDescriptor::setViewClosed()
{
mCreatedView = NULL;
}

}
26 changes: 23 additions & 3 deletions src/libHeaven/CentralUI/Views/ViewDescriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,34 @@
#ifndef HEAVEN_VIEW_DESCRIPTOR_HPP
#define HEAVEN_VIEW_DESCRIPTOR_HPP

#include <QObject>

#include "libHeaven/HeavenApi.hpp"

#include "libHeaven/CentralUI/Views/ViewIdentifier.hpp"

class QAction;

namespace Heaven
{

class DynamicActionMerger;
class View;

class HEAVEN_API ViewDescriptor
class HEAVEN_API ViewDescriptor : public QObject
{
Q_OBJECT
public:
class Registrar;
friend class Registrar;
typedef View* (*CreatorFunc)( );

public:
ViewDescriptor( const ViewIdentifier& id, const QString& displayName, CreatorFunc creator );
ViewDescriptor(const ViewIdentifier& id, const QString& displayName, CreatorFunc creator);
~ViewDescriptor();

public:
QAction* activatorAction();
QString displayName() const;
ViewIdentifier identifier() const;
ViewDescriptor::CreatorFunc creatorFunc() const;
Expand All @@ -45,13 +55,23 @@ namespace Heaven
View* createView() const;

public:
static DynamicActionMerger* actionMerger();
static void mergeViewsMenu(const QByteArray& mergePlace);
static ViewDescriptor* get( const ViewIdentifier& id );

private:
void setViewClosed();
void createActivatorAction();

private slots:
void onActivatorAction(bool triggered);

private:
const ViewIdentifier mIdentifier;
const QString mDisplayName;
const CreatorFunc mCreatorFunc;
static QHash< ViewIdentifier, ViewDescriptor* > mDescriptors;
mutable View* mCreatedView;
QAction* mActivatorAction;
};

}
Expand Down
120 changes: 120 additions & 0 deletions src/libHeaven/CentralUI/Views/ViewDescriptorRegistrar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* libHeaven - A Qt-based ui framework for strongly modularized applications
* Copyright (C) 2012-2013 The MacGitver-Developers <dev@macgitver.org>
*
* (C) Sascha Cunz <sascha@macgitver.org>
* (C) Cunz RaD Ltd.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/

#include <QAction>

#include "libHeaven/Actions/DynamicActionMerger.hpp"

#include "View.hpp"
#include "ViewDescriptorRegistrar.hpp"

namespace Heaven
{

/**
* @internal
* @class ViewDescriptor::Registrar
*
* @brief Internal class to manage registered ViewDescriptors and the Views-Menu
*
*/

ViewDescriptor::Registrar::Registrar()
{
setupActions(this);
damViewsMerger->setMode(DAMergerAdvancedList);
sSelf = this;
}

ViewDescriptor::Registrar& ViewDescriptor::Registrar::self()
{
if (sSelf == NULL) {
new Registrar();
}
return *sSelf;
}

ViewDescriptor::Registrar* ViewDescriptor::Registrar::sSelf = NULL;

void ViewDescriptor::Registrar::insert(const ViewIdentifier& id, ViewDescriptor* vd)
{
mDescriptors.insert(id, vd);
rebuildMerger();
}

void ViewDescriptor::Registrar::remove(const ViewIdentifier& id)
{
mDescriptors.remove(id);
rebuildMerger();
}

ViewDescriptor* ViewDescriptor::Registrar::get(const ViewIdentifier& id) const
{
return mDescriptors.value(id, NULL);
}

void ViewDescriptor::Registrar::viewClosed(View* view)
{
ViewIdentifier id = view->identifier();
ViewDescriptor* vd = get(id);

if (vd) {
QAction* aa = vd->activatorAction();
aa->setChecked(false);

vd->setViewClosed();
}
}

void ViewDescriptor::Registrar::viewOpened(View* view)
{
ViewIdentifier id = view->identifier();
ViewDescriptor* vd = get(id);

if (vd) {
QAction* aa = vd->activatorAction();
aa->setChecked(true);
}
}

DynamicActionMerger* ViewDescriptor::Registrar::actionMerger()
{
return damViewsMerger;
}

void ViewDescriptor::Registrar::rebuildMerger()
{
Q_ASSERT(damViewsMerger);
damViewsMerger->clear();

QMap<ViewIdentifier, ViewDescriptor*> descriptors;

foreach (ViewIdentifier id, mDescriptors.keys()) {
descriptors.insert(id, mDescriptors[id]);
}

foreach (ViewIdentifier id, descriptors.keys()) {
ViewDescriptor* vd = get(id);
if (vd) {
damViewsMerger->addAction(vd->activatorAction());
}
}
}

}
Loading