commit 69644b18b5c8f8c0888067fd8208b9539fe87d6e Author: Roy Qu Date: Tue Apr 6 23:10:57 2021 +0800 first commition diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro new file mode 100644 index 00000000..ba16a00b --- /dev/null +++ b/RedPandaIDE/RedPandaIDE.pro @@ -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 diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts new file mode 100644 index 00000000..a38afff8 --- /dev/null +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -0,0 +1,3 @@ + + + diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp new file mode 100644 index 00000000..cd040bba --- /dev/null +++ b/RedPandaIDE/editor.cpp @@ -0,0 +1,66 @@ +#include "editor.h" + +#include + + +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; +} diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h new file mode 100644 index 00000000..a4089791 --- /dev/null +++ b/RedPandaIDE/editor.h @@ -0,0 +1,39 @@ +#ifndef EDITOR_H +#define EDITOR_H + +#include +#include +#include +#include + +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 diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp new file mode 100644 index 00000000..52b6574e --- /dev/null +++ b/RedPandaIDE/editorlist.cpp @@ -0,0 +1,6 @@ +#include "editorlist.h" + +EditorList::EditorList(QObject *parent) : QObject(parent) +{ + +} diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h new file mode 100644 index 00000000..9f016d16 --- /dev/null +++ b/RedPandaIDE/editorlist.h @@ -0,0 +1,37 @@ +#ifndef EDITORLIST_H +#define EDITORLIST_H + +#include +#include +#include +#include + +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 diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp new file mode 100644 index 00000000..fd3e5334 --- /dev/null +++ b/RedPandaIDE/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp new file mode 100644 index 00000000..41a26bdf --- /dev/null +++ b/RedPandaIDE/mainwindow.cpp @@ -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; +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h new file mode 100644 index 00000000..4643e322 --- /dev/null +++ b/RedPandaIDE/mainwindow.h @@ -0,0 +1,21 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +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 diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui new file mode 100644 index 00000000..280c8959 --- /dev/null +++ b/RedPandaIDE/mainwindow.ui @@ -0,0 +1,148 @@ + + + MainWindow + + + + 0 + 0 + 946 + 657 + + + + MainWindow + + + + + + + Qt::Vertical + + + + + 0 + 2 + + + + + + + Qt::Horizontal + + + + + 1 + 0 + + + + QTabWidget::West + + + + Tab 1 + + + + + Tab 2 + + + + + + + 2 + 0 + + + + + + + + + 1 + + + + Tab 1 + + + + + Tab 2 + + + + + + + + + Tab 1 + + + + + Tab 2 + + + + + + + + + + + + + + + + 0 + 1 + + + + QTabWidget::South + + + 1 + + + + Tab 1 + + + + + Tab 2 + + + + + + + + + + + 0 + 0 + 946 + 25 + + + + + + + + diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp new file mode 100644 index 00000000..db54da92 --- /dev/null +++ b/RedPandaIDE/utils.cpp @@ -0,0 +1,59 @@ +#include "utils.h" +#include +#include +#include + +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); +} diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h new file mode 100644 index 00000000..684ad2ec --- /dev/null +++ b/RedPandaIDE/utils.h @@ -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 diff --git a/Red_Panda_CPP.pro b/Red_Panda_CPP.pro new file mode 100644 index 00000000..d6cfd288 --- /dev/null +++ b/Red_Panda_CPP.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + RedPandaIDE