• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • kasten
  • controllers
  • documentsystem
  • creator
creatorcontroller.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2006-2009,2011 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "creatorcontroller.h"
24 
25 // lib
26 #include "createdialog.h"
27 // Kasten gui
28 #include <abstractdocumentstrategy.h>
29 #include <selecteddatawriteable.h>
30 // Kasten core
31 #include <modelcodecmanager.h>
32 #include <abstractmodeldatagenerator.h>
33 // KDE
34 #include <KIcon>
35 #include <KLocale>
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KStandardAction>
39 #include <KXMLGUIClient>
40 // Qt
41 #include <QtGui/QApplication>
42 #include <QtCore/QMimeData>
43 
44 
45 #ifndef ABSTRACTMODELDATAGENERATOR_METATYPE
46 #define ABSTRACTMODELDATAGENERATOR_METATYPE
47 Q_DECLARE_METATYPE(Kasten2::AbstractModelDataGenerator*)
48 #endif
49 
50 namespace Kasten2
51 {
52 
53 CreatorController::CreatorController( ModelCodecManager* modelCodecManager,
54  AbstractDocumentStrategy* documentStrategy,
55  KXMLGUIClient* guiClient )
56  : AbstractXmlGuiController(),
57  mModelCodecManager( modelCodecManager ),
58  mDocumentStrategy( documentStrategy )
59 {
60  KActionCollection* actionCollection = guiClient->actionCollection();
61 
62  KActionMenu* newMenuAction = actionCollection->add<KActionMenu>( QLatin1String("file_new"), this, SLOT(onNewActionTriggered()) );
63  newMenuAction->setText( i18nc("@title:menu create new byte arrays from different sources", "New" ) );
64  newMenuAction->setIcon( KIcon( QLatin1String("document-new") ) );
65  newMenuAction->setShortcut( KStandardShortcut::openNew() );
66 
67  QAction* newEmptyDocumentAction =
68  new QAction( KIcon( QLatin1String("document-new") ), i18nc("@title:menu create a new empty document", "Empty" ), this );
69 // newEmptyDocumentAction->setToolTip( factory-toolTip() );
70 // i18nc( "@info:tooltip", "Create an empty document" ) );
71 // newEmptyDocumentAction->setHelpText( factory->helpText() );
72 // i18nc( "@info:status", "Create an new, empty document" ) );
73 // newEmptyDocumentAction->setWhatsThis( factory->whatsThis() );
74 // i18nc( "@info:whatsthis", "." ) );
75  connect( newEmptyDocumentAction, SIGNAL(triggered(bool)), SLOT(onNewActionTriggered()) );
76 
77  QAction* newFromClipboardDocumentAction =
78  new QAction( KIcon( QLatin1String("edit-paste") ), i18nc("@title:menu create a new document from data in the clipboard", "From Clipboard" ), this );
79  connect( newFromClipboardDocumentAction, SIGNAL(triggered(bool)), SLOT(onNewFromClipboardActionTriggered()) );
80 
81  newMenuAction->addAction( newEmptyDocumentAction );
82  newMenuAction->addSeparator();
83  newMenuAction->addAction( newFromClipboardDocumentAction );
84 
85  // generators
86  const QList<AbstractModelDataGenerator*> generatorList =
87  mModelCodecManager->generatorList();
88 
89  const bool hasGenerators = ( generatorList.size() > 0 );
90 
91  if( hasGenerators )
92  {
93  newMenuAction->addSeparator();
94 
95  // TODO: ask factory which mimetypes it can read
96  // AbstractDocumentFactory->canCreateFromData( QMimeData() ) needs already data
97  foreach( AbstractModelDataGenerator* generator, generatorList )
98  {
99  const QString title = generator->typeName();
100  const QString iconName = QString::fromLatin1( "document-new" );//generator->iconName();
101 
102  QAction* action = new QAction( KIcon(iconName), title, this );
103  action->setData( QVariant::fromValue(generator) );
104  connect( action, SIGNAL(triggered(bool)), SLOT(onNewFromGeneratorActionTriggered()) );
105 
106  newMenuAction->addAction( action );
107  }
108  }
109 }
110 
111 void CreatorController::setTargetModel( AbstractModel* model )
112 {
113 Q_UNUSED( model )
114 }
115 
116 void CreatorController::onNewActionTriggered()
117 {
118  mDocumentStrategy->createNew();
119 }
120 
121 void CreatorController::onNewFromClipboardActionTriggered()
122 {
123  mDocumentStrategy->createNewFromClipboard();
124 }
125 
126 void CreatorController::onNewFromGeneratorActionTriggered()
127 {
128  QAction* action = static_cast<QAction*>( sender() );
129 
130  AbstractModelDataGenerator* generator = action->data().value<AbstractModelDataGenerator* >();
131 
132  mDocumentStrategy->createNewWithGenerator( generator );
133 }
134 
135 CreatorController::~CreatorController() {}
136 
137 }
modelcodecmanager.h
abstractdocumentstrategy.h
Kasten2::AbstractDocumentStrategy
Definition: abstractdocumentstrategy.h:42
Kasten2::AbstractDocumentStrategy::createNewWithGenerator
virtual void createNewWithGenerator(AbstractModelDataGenerator *generator)=0
Kasten2::ModelCodecManager::generatorList
QList< AbstractModelDataGenerator * > generatorList() const
Definition: modelcodecmanager.cpp:61
abstractmodeldatagenerator.h
selecteddatawriteable.h
Kasten2::AbstractModelDataGenerator
Definition: abstractmodeldatagenerator.h:41
Kasten2::AbstractDocumentStrategy::createNew
virtual void createNew()=0
createdialog.h
Kasten2::AbstractModelDataGenerator::typeName
QString typeName() const
Definition: abstractmodeldatagenerator.cpp:41
Kasten2::CreatorController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: creatorcontroller.cpp:111
creatorcontroller.h
Kasten2::CreatorController::CreatorController
CreatorController(ModelCodecManager *modelCodecManager, AbstractDocumentStrategy *documentStrategy, KXMLGUIClient *guiClient)
Definition: creatorcontroller.cpp:53
Kasten2::AbstractDocumentStrategy::createNewFromClipboard
virtual void createNewFromClipboard()=0
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::CreatorController::~CreatorController
virtual ~CreatorController()
Definition: creatorcontroller.cpp:135
Kasten2::ModelCodecManager
Definition: modelcodecmanager.h:48
QList
Definition: bookmarkable.h:29
Kasten2::AbstractXmlGuiController
Definition: abstractxmlguicontroller.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal