| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2013-01-28 17:12:19 +01:00
										 |  |  | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Contact: http://www.qt-project.org/legal
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Digia.  For licensing terms and | 
					
						
							|  |  |  | ** conditions see http://qt.digia.com/licensing.  For further information
 | 
					
						
							|  |  |  | ** use the contact form at http://qt.digia.com/contact-us.
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** In addition, as a special exception, Digia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Digia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2011-02-18 14:48:16 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  | #include "fakevimhandler.h"
 | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-15 10:42:41 +01:00
										 |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QMainWindow>
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | #include <QPlainTextEdit>
 | 
					
						
							|  |  |  | #include <QStatusBar>
 | 
					
						
							|  |  |  | #include <QTextEdit>
 | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace FakeVim::Internal; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  | class Proxy : public QObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     Proxy(QWidget *widget, QMainWindow *mw, QObject *parent = 0) | 
					
						
							|  |  |  |       : QObject(parent), m_widget(widget), m_mainWindow(mw) | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |     {} | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | public slots: | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |     void changeSelection(const QList<QTextEdit::ExtraSelection> &s) | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 |  |  |         if (QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget)) | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  |             ed->setExtraSelections(s); | 
					
						
							| 
									
										
										
										
											2009-01-23 16:37:32 +01:00
										 |  |  |         else if (QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget)) | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  |             ed->setExtraSelections(s); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     void changeStatusData(const QString &info) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_statusData = info; | 
					
						
							|  |  |  |         updateStatusBar(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 12:36:15 +02:00
										 |  |  |     void changeStatusMessage(const QString &contents, int cursorPos) | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-08-05 12:36:15 +02:00
										 |  |  |         m_statusMessage = cursorPos == -1 ? contents | 
					
						
							|  |  |  |             : contents.left(cursorPos) + QChar(10073) + contents.mid(cursorPos); | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |         updateStatusBar(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |     void changeExtraInformation(const QString &info) | 
					
						
							| 
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |         QMessageBox::information(m_widget, tr("Information"), info); | 
					
						
							| 
									
										
										
										
											2009-01-15 17:29:30 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-29 21:33:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     void updateStatusBar() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         int slack = 80 - m_statusMessage.size() - m_statusData.size(); | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |         QString msg = m_statusMessage + QString(slack, QLatin1Char(' ')) + m_statusData; | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |         m_mainWindow->statusBar()->showMessage(msg); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QWidget *m_widget; | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     QMainWindow *m_mainWindow; | 
					
						
							|  |  |  |     QString m_statusMessage; | 
					
						
							|  |  |  |     QString m_statusData; | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | int main(int argc, char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QApplication app(argc, argv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList args = app.arguments(); | 
					
						
							|  |  |  |     (void) args.takeFirst(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QWidget *widget = 0; | 
					
						
							|  |  |  |     QString title; | 
					
						
							|  |  |  |     bool usePlainTextEdit = args.size() < 2; | 
					
						
							|  |  |  |     if (usePlainTextEdit) { | 
					
						
							| 
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 |  |  |         QPlainTextEdit *w = new QPlainTextEdit; | 
					
						
							|  |  |  |         w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |         title = QLatin1String("PlainTextEdit"); | 
					
						
							| 
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 |  |  |         widget = w; | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 |  |  |         QTextEdit *w = new QTextEdit; | 
					
						
							|  |  |  |         w->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |         title = QLatin1String("TextEdit"); | 
					
						
							| 
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 |  |  |         widget = w; | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |     widget->setObjectName(QLatin1String("Editor")); | 
					
						
							| 
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 |  |  |     //widget->resize(450, 350);
 | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     widget->setFocus(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     QMainWindow mw; | 
					
						
							|  |  |  |     Proxy proxy(widget, &mw); | 
					
						
							| 
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |     FakeVimHandler handler(widget, 0); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |     mw.setWindowTitle(QLatin1String("Fakevim (") + title + QLatin1Char(')')); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     mw.setCentralWidget(widget); | 
					
						
							| 
									
										
										
										
											2009-01-26 10:31:49 +01:00
										 |  |  |     mw.resize(600, 650); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     mw.move(0, 0); | 
					
						
							|  |  |  |     mw.show(); | 
					
						
							| 
									
										
										
										
											2010-01-29 21:33:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 |  |  |     QFont font = widget->font(); | 
					
						
							|  |  |  |     //: -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
 | 
					
						
							|  |  |  |     //font.setFamily("Misc");
 | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |     font.setFamily(QLatin1String("Monospace")); | 
					
						
							| 
									
										
										
										
											2009-01-06 13:03:59 +01:00
										 |  |  |     //font.setStretch(QFont::SemiCondensed);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     widget->setFont(font); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     mw.statusBar()->setFont(font); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 12:36:15 +02:00
										 |  |  |     QObject::connect(&handler, SIGNAL(commandBufferChanged(QString,int)), | 
					
						
							|  |  |  |         &proxy, SLOT(changeStatusMessage(QString,int))); | 
					
						
							| 
									
										
										
										
											2009-08-11 14:39:44 +02:00
										 |  |  |     //QObject::connect(&handler, SIGNAL(quitRequested(bool)),
 | 
					
						
							|  |  |  |     //    &app, SLOT(quit()));
 | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  |     QObject::connect(&handler, | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |         SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), | 
					
						
							|  |  |  |         &proxy, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>))); | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     QObject::connect(&handler, SIGNAL(extraInformationChanged(QString)), | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |         &proxy, SLOT(changeExtraInformation(QString))); | 
					
						
							| 
									
										
										
										
											2009-01-27 14:08:17 +01:00
										 |  |  |     QObject::connect(&handler, SIGNAL(statusDataChanged(QString)), | 
					
						
							|  |  |  |         &proxy, SLOT(changeStatusData(QString))); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 14:52:08 +02:00
										 |  |  |     theFakeVimSetting(ConfigUseFakeVim)->setValue(true); | 
					
						
							| 
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 |  |  |     theFakeVimSetting(ConfigShiftWidth)->setValue(8); | 
					
						
							|  |  |  |     theFakeVimSetting(ConfigTabStop)->setValue(8); | 
					
						
							| 
									
										
										
										
											2009-07-10 14:56:12 +02:00
										 |  |  |     theFakeVimSetting(ConfigAutoIndent)->setValue(true); | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |     theFakeVimSetting(ConfigIsKeyword)->setValue(QLatin1String("@,48-57,_,192-255,a-z,A-Z")); | 
					
						
							| 
									
										
										
										
											2009-04-01 15:11:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-31 14:52:08 +02:00
										 |  |  |     handler.installEventFilter(); | 
					
						
							| 
									
										
										
										
											2009-01-23 15:12:04 +01:00
										 |  |  |     handler.setupWidget(); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  |     if (args.size() >= 1) | 
					
						
							| 
									
										
										
										
											2013-02-25 18:34:03 +01:00
										 |  |  |         handler.handleCommand(QLatin1String("r ") + args.at(0)); | 
					
						
							| 
									
										
										
										
											2009-01-06 12:20:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return app.exec(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-13 13:47:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "main.moc"
 |