Permalink
Browse files

Use KAction for Back and Forward, and add a Home action.

  • Loading branch information...
1 parent fcb2f4a commit d1554655af3578721fc9aa01800753368db0dc6b @pcapriotti committed Mar 13, 2010
Showing with 150 additions and 43 deletions.
  1. +2 −1 CMakeLists.txt
  2. +19 −21 hikkiui.rc
  3. +47 −21 mainwindow.cpp
  4. +1 −0 mainwindow.h
  5. +41 −0 proxyaction.cpp
  6. +40 −0 proxyaction.h
View
@@ -9,7 +9,8 @@ set(src main.cpp
mainwindow.cpp
note.cpp
notebook.cpp
- webkitpart.cpp)
+ webkitpart.cpp
+ proxyaction.cpp)
kde4_add_executable(hikki ${src})
target_link_libraries(hikki markdown ${KDE4_KDEUI_LIBS} kparts ktexteditor QtWebKit)
View
@@ -1,30 +1,28 @@
<!DOCTYPE kpartgui SYSTEM 'kpartgui.dtd'>
-<kpartgui version="17" name="hikki" >
+<kpartgui version="17" name="hikki">
<MenuBar>
- <Menu name="file" >
- <Action name="edit_mode" />
- <Action name="display_mode" />
+ <Menu name="file">
+ <Action name="edit_mode"/>
+ <Action name="display_mode"/>
</Menu>
- <Menu name="go" >
+ <Menu name="go">
<Text>&amp;Go</Text>
- <Action name="back" />
- <Action name="forward" />
- <Action name="home" />
+ <Action name="go_home"/>
+ <Action name="back"/>
+ <Action name="forward"/>
</Menu>
- <Menu name="bookmarks" />
- <Menu name="tools" />
- <Merge/>
- <Menu name="help" />
</MenuBar>
- <ActionProperties scheme="Default" >
- <Action shortcut="Alt+2" name="display_mode" />
- <Action shortcut="Alt+1" name="edit_mode" />
+ <ActionProperties scheme="Default">
+ <Action shortcut="Alt+2" name="display_mode"/>
+ <Action shortcut="Alt+1" name="edit_mode"/>
+ <Action shortcut="Alt+Left" name="back"/>
+ <Action shortcut="Alt+Right" name="forward"/>
</ActionProperties>
- <ToolBar noMerge="1" name="mainToolBar" >
- <Action name="edit_mode" />
- <Action name="display_mode" />
- <Action name="go_home" />
- <Action name="go_back" />
- <Action name="go_forward" />
+ <ToolBar noMerge="1" name="mainToolBar">
+ <Action name="edit_mode"/>
+ <Action name="display_mode"/>
+ <Action name="go_home"/>
+ <Action name="back"/>
+ <Action name="forward"/>
</ToolBar>
</kpartgui>
View
@@ -36,6 +36,7 @@
#include <QApplication>
#include "webkitpart.h"
+#include "proxyaction.h"
using namespace KTextEditor;
@@ -90,26 +91,52 @@ MainWindow::~MainWindow()
void MainWindow::setupActions()
{
- KAction* editMode = new KAction(
- KIcon("document-edit"),
- i18n("&Edit mode"),
- this);
- actionCollection()->addAction("edit_mode", editMode);
- connect(editMode, SIGNAL(triggered()),
- this, SLOT(editMode()));
-
- KAction* displayMode = new KAction(
- KIcon("document-preview"),
- i18n("&Display mode"),
- this);
- actionCollection()->addAction("display_mode", displayMode);
- connect(displayMode, SIGNAL(triggered()),
- this, SLOT(displayMode()));
-
- actionCollection()->addAction("go_back",
- m_browser->view()->pageAction(QWebPage::Back));
- actionCollection()->addAction("go_forward",
- m_browser->view()->pageAction(QWebPage::Forward));
+ {
+ KAction* editMode = new KAction(
+ KIcon("document-edit"),
+ i18n("&Edit mode"),
+ this);
+ actionCollection()->addAction("edit_mode", editMode);
+ connect(editMode, SIGNAL(triggered()),
+ this, SLOT(editMode()));
+ }
+
+ {
+ KAction* displayMode = new KAction(
+ KIcon("document-preview"),
+ i18n("&Display mode"),
+ this);
+ actionCollection()->addAction("display_mode", displayMode);
+ connect(displayMode, SIGNAL(triggered()),
+ this, SLOT(displayMode()));
+ }
+
+ {
+ QAction* webBack = m_browser->view()->pageAction(QWebPage::Back);
+ KAction* back = new ProxyAction(webBack, this);
+ actionCollection()->addAction("back", back);
+ }
+
+ {
+ QAction* webForward = m_browser->view()->pageAction(QWebPage::Forward);
+ KAction* forward = new ProxyAction(webForward, this);
+ actionCollection()->addAction("forward", forward);
+ }
+
+ KStandardAction::home(this, SLOT(index()), actionCollection());
+}
+
+void MainWindow::index()
+{
+ m_note = m_notebook->open("index");
+ if (m_mode == EditMode)
+ {
+ editMode();
+ }
+ else
+ {
+ displayMode();
+ }
}
void MainWindow::removeUnwantedActions()
@@ -168,7 +195,6 @@ void MainWindow::displayNote(NotePtr note)
void MainWindow::noteChanged(const QString& path)
{
- kDebug() << path;
m_note = m_notebook->openFromRendered(path);
if (m_mode == EditMode)
editMode();
View
@@ -62,6 +62,7 @@ Q_OBJECT
public slots:
void editMode();
void displayMode();
+ void index();
void displayNote(NotePtr note);
void displayCurrentNote();
View
@@ -0,0 +1,41 @@
+// Copyright (c) 2010 Paolo Capriotti <p.capriotti@gmail.com>
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "proxyaction.h"
+
+ProxyAction::ProxyAction(QAction* action, QObject* parent)
+: KAction(parent)
+, m_action(action)
+{
+ setText(action->text());
+ setIcon(action->icon());
+ connect(this, SIGNAL(triggered()), m_action, SLOT(trigger()));
+ connect(m_action, SIGNAL(changed()), this, SLOT(update()));
+ update();
+}
+
+void ProxyAction::update()
+{
+ setEnabled(m_action->isEnabled());
+ setChecked(m_action->isChecked());
+}
View
@@ -0,0 +1,40 @@
+// Copyright (c) 2010 Paolo Capriotti <p.capriotti@gmail.com>
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef PROXY_ACTION_H
+#define PROXY_ACTION_H
+
+#include <KAction>
+
+class ProxyAction : public KAction
+{
+Q_OBJECT
+ QAction* m_action;
+public:
+ ProxyAction(QAction* action, QObject* parent);
+
+private slots:
+ void update();
+};
+
+#endif // PROXY_ACTION_H

0 comments on commit d155465

Please sign in to comment.