first commition
This commit is contained in:
commit
69644b18b5
|
@ -0,0 +1,33 @@
|
|||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
# You can make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
editor.cpp \
|
||||
editorlist.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
utils.cpp
|
||||
|
||||
HEADERS += \
|
||||
editor.h \
|
||||
editorlist.h \
|
||||
mainwindow.h \
|
||||
utils.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
TRANSLATIONS += \
|
||||
RedPandaIDE_zh_CN.ts
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="RedPandaIDE_zh_CN"></TS>
|
|
@ -0,0 +1,66 @@
|
|||
#include "editor.h"
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
|
||||
|
||||
Editor::Editor(QObject *parent, const QString& filename,
|
||||
FileEncodingType encodingType,
|
||||
bool inProject, bool isNew,
|
||||
QTabWidget* parentPageControl):
|
||||
QObject(parent),
|
||||
mFilename(filename),
|
||||
mEncodingType(encodingType),
|
||||
mInProject(inProject),
|
||||
mIsNew(isNew),
|
||||
mParentPageControl(parentPageControl)
|
||||
{
|
||||
mTextEdit = new QsciScintilla();
|
||||
QFileInfo fileInfo(mFilename);
|
||||
mParentPageControl->addTab(mTextEdit,fileInfo.fileName());
|
||||
if (!isNew) {
|
||||
loadFile();
|
||||
} else {
|
||||
mFileEncoding = etAscii;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Editor::loadFile() {
|
||||
QStringList strs;
|
||||
QFile file(mFilename);
|
||||
QByteArray ba=file.read(file.bytesAvailable());
|
||||
if (mEncodingType == etAuto) {
|
||||
mFileEncoding = GetFileEncodingType(ba);
|
||||
} else {
|
||||
mFileEncoding = mEncodingType;
|
||||
}
|
||||
switch(mFileEncoding) {
|
||||
case etUTF8:
|
||||
mTextEdit->setText(UTF8toQString(ba));
|
||||
break;
|
||||
case etUTF8Bom:
|
||||
mTextEdit->setText(UTF8toQString(ba.mid(3)));
|
||||
break;
|
||||
default:
|
||||
mTextEdit->setText(QString(ba));
|
||||
}
|
||||
}
|
||||
|
||||
FileEncodingType Editor::encodingType() const {
|
||||
return mEncodingType;
|
||||
}
|
||||
void Editor::setFileEncodingType(FileEncodingType type) {
|
||||
mEncodingType = type;
|
||||
}
|
||||
FileEncodingType Editor::fileEncoding() const {
|
||||
return mFileEncoding;
|
||||
}
|
||||
const QString& Editor::filename() {
|
||||
return mFilename;
|
||||
}
|
||||
bool Editor::inProject() const {
|
||||
return mInProject;
|
||||
}
|
||||
bool Editor::isNew() const {
|
||||
return mIsNew;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <utils.h>
|
||||
#include <QTabWidget>
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
|
||||
class Editor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Editor(QObject *parent, const QString& filename,
|
||||
FileEncodingType encodingType,
|
||||
bool inProject, bool isNew,
|
||||
QTabWidget* parentPageControl);
|
||||
|
||||
FileEncodingType encodingType() const;
|
||||
void setFileEncodingType(FileEncodingType type);
|
||||
FileEncodingType fileEncoding() const;
|
||||
const QString& filename();
|
||||
bool inProject() const;
|
||||
bool isNew() const;
|
||||
|
||||
void loadFile();
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
FileEncodingType mEncodingType; // the encoding type set by the user
|
||||
FileEncodingType mFileEncoding; // the real encoding of the file (auto detected)
|
||||
QString mFilename;
|
||||
QTabWidget* mParentPageControl;
|
||||
bool mInProject;
|
||||
bool mIsNew;
|
||||
QsciScintilla* mTextEdit;
|
||||
};
|
||||
|
||||
#endif // EDITOR_H
|
|
@ -0,0 +1,6 @@
|
|||
#include "editorlist.h"
|
||||
|
||||
EditorList::EditorList(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef EDITORLIST_H
|
||||
#define EDITORLIST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTabWidget>
|
||||
#include <QSplitter>
|
||||
#include <QWidget>
|
||||
|
||||
class EditorList : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ShowType{
|
||||
lstNone,
|
||||
lstLeft,
|
||||
lstRight,
|
||||
lstBoth
|
||||
};
|
||||
explicit EditorList(QObject *parent = nullptr);
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
ShowType mLayout;
|
||||
QTabWidget *mLeftPageWidget;
|
||||
QTabWidget *mRightPageWidget;
|
||||
QSplitter *mSplitter;
|
||||
QWidget *mPanel;
|
||||
int mUpdateCount;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // EDITORLIST_H
|
|
@ -0,0 +1,11 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
|
@ -0,0 +1,148 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>946</width>
|
||||
<height>657</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>2</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QTabWidget" name="tabWidget_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::West</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget_3">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_5">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_6">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget_4">
|
||||
<widget class="QWidget" name="tab_7">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_8">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Tab 1</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
<attribute name="title">
|
||||
<string>Tab 2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>946</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,59 @@
|
|||
#include "utils.h"
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QTextCodec>
|
||||
|
||||
FileEncodingType GetFileEncodingType(const QByteArray& content){
|
||||
bool allAscii;
|
||||
int ii;
|
||||
int size;
|
||||
const QByteArray& s=content;
|
||||
size = s.length();
|
||||
if ( (size >= 3) && ((unsigned char)s[0]==0xEF) && ((unsigned char)s[1]==0xBB) && ((unsigned char)s[2]==0xBF)) {
|
||||
return etUTF8Bom;
|
||||
}
|
||||
allAscii = true;
|
||||
ii = 0;
|
||||
while (ii < size) {
|
||||
unsigned char ch = s[ii];
|
||||
if (ch < 0x80 ) {
|
||||
ii++; // is an ascii char
|
||||
} else if (ch < 0xC0) { // value between 0x80 and 0xC0 is an invalid UTF-8 char
|
||||
return etAnsi;
|
||||
} else if (ch < 0xE0) { // should be an 2-byte UTF-8 char
|
||||
if (ii>=size-1) {
|
||||
return etAnsi;
|
||||
}
|
||||
unsigned char ch2=s[ii+1];
|
||||
if ((ch2 & 0xC0) !=0x80) {
|
||||
return etAnsi;
|
||||
}
|
||||
allAscii = false;
|
||||
ii+=2;
|
||||
} else if (ch < 0xF0) { // should be an 3-byte UTF-8 char
|
||||
if (ii>=size-2) {
|
||||
return etAnsi;
|
||||
}
|
||||
unsigned char ch2=s[ii+1];
|
||||
unsigned char ch3=s[ii+2];
|
||||
if (((ch2 & 0xC0)!=0x80) || ((ch3 & 0xC0)!=0x80)) {
|
||||
return etAnsi;
|
||||
}
|
||||
allAscii = false;
|
||||
ii+=3;
|
||||
} else { // invalid UTF-8 char
|
||||
return etAnsi;
|
||||
}
|
||||
}
|
||||
if (allAscii)
|
||||
return etAscii;
|
||||
return etUTF8;
|
||||
}
|
||||
|
||||
QString UTF8toQString(const QByteArray& ba){
|
||||
QTextCodec* tc = QTextCodec::codecForName("UTF-8");
|
||||
if (tc == NULL)
|
||||
return QString();
|
||||
else
|
||||
return tc->toUnicode(ba);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
class QByteArray;
|
||||
class QString;
|
||||
|
||||
enum FileEncodingType {
|
||||
etAuto,
|
||||
etUTF8,
|
||||
etAscii,
|
||||
etAnsi,
|
||||
etUTF8Bom
|
||||
};
|
||||
|
||||
FileEncodingType GetFileEncodingType(const QByteArray& content);
|
||||
|
||||
QString UTF8toQString(const QByteArray& ba);
|
||||
|
||||
#endif // UTILS_H
|
|
@ -0,0 +1,4 @@
|
|||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += \
|
||||
RedPandaIDE
|
Loading…
Reference in New Issue