corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [1/4] incubator-corinthia git commit: Desktop app: Basic infrastructure for Editor lib
Date Sat, 11 Apr 2015 17:49:45 GMT
Repository: incubator-corinthia
Updated Branches:
  refs/heads/master 97148773a -> 23c028c72


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/MainWindow.cpp
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/MainWindow.cpp b/consumers/corinthia/src/MainWindow.cpp
new file mode 100644
index 0000000..cb2a280
--- /dev/null
+++ b/consumers/corinthia/src/MainWindow.cpp
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "MainWindow.h"
+#include <QWebView.h>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QCoreApplication>
+#include "Editor.h"
+#include "JSInterface.h"
+#include "Toolbar.h"
+
+MainWindow::MainWindow(QApplication *app) : QWidget(0)
+{
+    _app = app;
+    _toolbar = new Toolbar(this);
+    _editor = new Editor(this);
+    QVBoxLayout *vlayout = new QVBoxLayout();
+    this->setLayout(vlayout);
+    vlayout->addWidget(_toolbar);
+    vlayout->addWidget(_editor);
+    vlayout->setSpacing(0);
+    vlayout->setContentsMargins(4,4,4,4);
+
+    QObject::connect(_toolbar->tableButton(),SIGNAL(clicked()),this,SLOT(insertTable()));
+    QObject::connect(_toolbar->linkButton(),SIGNAL(clicked()),this,SLOT(insertLink()));
+    QObject::connect(_toolbar->characterButton(),SIGNAL(clicked()),this,SLOT(insertCharacter()));
+    QObject::connect(_toolbar->backspaceButton(),SIGNAL(clicked()),this,SLOT(backspace()));
+    QObject::connect(_toolbar->leftButton(),SIGNAL(clicked()),this,SLOT(moveLeft()));
+    QObject::connect(_toolbar->rightButton(),SIGNAL(clicked()),this,SLOT(moveRight()));
+    QObject::connect(_toolbar->undoButton(),SIGNAL(clicked()),this,SLOT(undo()));
+    QObject::connect(_toolbar->redoButton(),SIGNAL(clicked()),this,SLOT(redo()));
+
+    QString appPath = QCoreApplication::applicationDirPath();
+    QString docPath = appPath + "/../share/corinthia/sample.html";
+    QUrl url = QUrl::fromLocalFile(docPath);
+    qStdOut() << "sample document url = " << url.toString() << endl;
+    _editor->webView()->load(url);
+}
+
+MainWindow::~MainWindow()
+{
+    delete _toolbar;
+    delete _editor;
+}
+
+void MainWindow::insertTable()
+{
+    _editor->js()->tables.insertTable(4,3,"50%",true,"Table caption",QString::null);
+}
+
+void MainWindow::insertLink()
+{
+    _editor->js()->cursor.insertLink("Corinthia website","http://corinthia.incubator.apache.org");
+}
+
+void MainWindow::insertCharacter()
+{
+    _editor->js()->cursor.insertCharacter('X',true);
+}
+
+void MainWindow::backspace()
+{
+    _editor->js()->cursor.deleteCharacter();
+}
+
+void MainWindow::moveLeft()
+{
+    _editor->js()->cursor.moveLeft();
+}
+
+void MainWindow::moveRight()
+{
+    _editor->js()->cursor.moveRight();
+}
+
+void MainWindow::undo()
+{
+    _editor->js()->undoManager.undo();
+}
+
+void MainWindow::redo()
+{
+    _editor->js()->undoManager.redo();
+}
+
+//#include <MainWindow.moc>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/MainWindow.h
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/MainWindow.h b/consumers/corinthia/src/MainWindow.h
new file mode 100644
index 0000000..0a2693b
--- /dev/null
+++ b/consumers/corinthia/src/MainWindow.h
@@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <QWidget>
+
+class Toolbar;
+class Editor;
+
+class MainWindow : public QWidget
+{
+    Q_OBJECT
+public:
+    MainWindow(QApplication *app);
+    ~MainWindow();
+    public slots:
+    void insertTable();
+    void insertLink();
+    void insertCharacter();
+    void backspace();
+    void moveLeft();
+    void moveRight();
+    void undo();
+    void redo();
+private:
+    QApplication *_app;
+    Toolbar *_toolbar;
+    Editor *_editor;
+};

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/Toolbar.cpp
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/Toolbar.cpp b/consumers/corinthia/src/Toolbar.cpp
new file mode 100644
index 0000000..4a6faf6
--- /dev/null
+++ b/consumers/corinthia/src/Toolbar.cpp
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "Toolbar.h"
+#include <QPushButton>
+#include <QHBoxLayout>
+
+Toolbar::Toolbar(QWidget *parent) : QWidget(parent)
+{
+    _tableButton = new QPushButton("Insert table",0);
+    _linkButton = new QPushButton("Insert link",0);
+    _characterButton = new QPushButton("Insert character",0);
+    _backspaceButton = new QPushButton("Backspace",0);
+    _leftButton = new QPushButton("Move left",0);
+    _rightButton = new QPushButton("Move right",0);
+    _undoButton = new QPushButton("Undo",0);
+    _redoButton = new QPushButton("Redo",0);
+
+    _layout = new QHBoxLayout();
+    this->setLayout(_layout);
+
+    _layout->addWidget(_tableButton);
+    _layout->addWidget(_linkButton);
+    _layout->addWidget(_characterButton);
+    _layout->addWidget(_backspaceButton);
+    _layout->addWidget(_leftButton);
+    _layout->addWidget(_rightButton);
+    _layout->addWidget(_undoButton);
+    _layout->addWidget(_redoButton);
+    _layout->setSpacing(4);
+    _layout->setContentsMargins(0,0,0,0);
+}
+
+Toolbar::~Toolbar()
+{
+}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/Toolbar.h
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/Toolbar.h b/consumers/corinthia/src/Toolbar.h
new file mode 100644
index 0000000..207eafc
--- /dev/null
+++ b/consumers/corinthia/src/Toolbar.h
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <QWidget>
+
+class QPushButton;
+class QHBoxLayout;
+
+class Toolbar : public QWidget
+{
+    Q_OBJECT
+public:
+    Toolbar(QWidget *parent = 0);
+    ~Toolbar();
+
+    QPushButton *tableButton() { return _tableButton; }
+    QPushButton *linkButton() { return _linkButton; }
+    QPushButton *characterButton() { return _characterButton; }
+    QPushButton *backspaceButton() { return _backspaceButton; }
+    QPushButton *leftButton() { return _leftButton; }
+    QPushButton *rightButton() { return _rightButton; }
+    QPushButton *undoButton() { return _undoButton; }
+    QPushButton *redoButton() { return _redoButton; }
+
+private:
+    QPushButton *_tableButton;
+    QPushButton *_linkButton;
+    QPushButton *_characterButton;
+    QPushButton *_backspaceButton;
+    QPushButton *_leftButton;
+    QPushButton *_rightButton;
+    QPushButton *_undoButton;
+    QPushButton *_redoButton;
+    QHBoxLayout *_layout;
+};

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/desktop.cpp
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/desktop.cpp b/consumers/corinthia/src/desktop.cpp
deleted file mode 100644
index c7cb188..0000000
--- a/consumers/corinthia/src/desktop.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-#include <QtWebKit/QWebElement>
-#include <QtWebKitWidgets/QWebFrame>
-#include "editWindows.h"
-
-
-
-DesktopWindow::DesktopWindow(QWidget *parent)
-              : QWidget(parent)
-{
-    setupUi(this);
-}
-
-
-
-void DesktopWindow::on_elementLineEdit_returnPressed()
-{
-    QWebFrame *frame               = webView->page()->mainFrame();
-    QWebElement document           = frame->documentElement();
-    QWebElementCollection elements = document.findAll(elementLineEdit->text());
-
-    foreach (QWebElement element, elements)
-        element.setAttribute("style", "background-color: #f0f090");
-}
-
-
-
-void DesktopWindow::on_highlightButton_clicked()
-{
-    on_elementLineEdit_returnPressed();
-}
-
-
-
-void DesktopWindow::setUrl(const QUrl &url)
-{
-    webView->setUrl(url);
-}

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/desktop.ui
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/desktop.ui b/consumers/corinthia/src/desktop.ui
deleted file mode 100644
index 2db697f..0000000
--- a/consumers/corinthia/src/desktop.ui
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>DesktopWindow</class>
- <widget class="QWidget" name="Window">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>640</width>
-    <height>480</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Web Element Selector</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
-   <item>
-    <widget class="QWebView" name="webView">
-     <property name="url">
-      <url>
-       <string>http://webkit.org/</string>
-      </url>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <layout class="QHBoxLayout" name="horizontalLayout">
-     <item>
-      <layout class="QFormLayout" name="formLayout">
-       <property name="fieldGrowthPolicy">
-        <enum>QFormLayout::ExpandingFieldsGrow</enum>
-       </property>
-       <item row="0" column="0">
-        <widget class="QLabel" name="elementLabel">
-         <property name="text">
-          <string>&amp;Element:</string>
-         </property>
-         <property name="buddy">
-          <cstring>elementLineEdit</cstring>
-         </property>
-        </widget>
-       </item>
-       <item row="0" column="1">
-        <widget class="QLineEdit" name="elementLineEdit">
-         <property name="text">
-          <string>li a</string>
-         </property>
-        </widget>
-       </item>
-      </layout>
-     </item>
-     <item>
-      <widget class="QPushButton" name="highlightButton">
-       <property name="text">
-        <string>&amp;Highlight</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-  </layout>
- </widget>
- <customwidgets>
-  <customwidget>
-   <class>QWebView</class>
-   <extends>QWidget</extends>
-   <header>QtWebKit/QWebView</header>
-  </customwidget>
- </customwidgets>
- <resources/>
- <connections/>
-</ui>

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/editWindows.h
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/editWindows.h b/consumers/corinthia/src/editWindows.h
deleted file mode 100644
index a49a6d6..0000000
--- a/consumers/corinthia/src/editWindows.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-#ifndef editWindows_h 
-#define editWindows_h
-#include <QtCore/QUrl>
-#include <QtWidgets/QWidget>
-#include "ui_desktop.h"
-
-class DesktopWindow : public QWidget, private Ui::DesktopWindow
-{
-        Q_OBJECT
-
-    public:
-        DesktopWindow(QWidget *parent = 0);
-        void setUrl(const QUrl &url);
-
-    public slots:
-        void on_elementLineEdit_returnPressed();
-        void on_highlightButton_clicked();
-};
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/23c028c7/consumers/corinthia/src/main.cpp
----------------------------------------------------------------------
diff --git a/consumers/corinthia/src/main.cpp b/consumers/corinthia/src/main.cpp
index 399b0a6..f17f506 100644
--- a/consumers/corinthia/src/main.cpp
+++ b/consumers/corinthia/src/main.cpp
@@ -14,17 +14,14 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-#include <QtGUi/QtGui>
-#include "editWindows.h"
-
 
+#include <QApplication>
+#include "MainWindow.h"
 
 int main(int argc, char *argv[])
 {
-    QApplication app(argc, argv);
-
-    DesktopWindow desktop;
-    desktop.setUrl(QUrl("http://corinthia.apache.org"));
-    desktop.show();
-    return app.exec();
+    QApplication *app = new QApplication(argc, argv);
+    MainWindow *window = new MainWindow(app);
+    window->show();
+    return app->exec();
 }


Mime
View raw message