diff --git a/Client/Client.pro b/Client/Client.pro index 8b498b33c50be1280f6a86d0ea9ce689734c9c1b..e60b656970c80a0483f34c93a2ee368ed1a10640 100644 --- a/Client/Client.pro +++ b/Client/Client.pro @@ -21,13 +21,14 @@ SOURCES += \ Session/onlinesession.cpp \ clientdatacenter.cpp \ clientmain.cpp \ + codeeditor.cpp \ databaseoperation.cpp \ - highlighter.cpp \ kuang.cpp \ main.cpp \ mainwindow.cpp \ message.cpp \ messagemodel.cpp \ + myhighlighter.cpp \ userlogin.cpp \ usermodel.cpp \ userregister.cpp \ @@ -39,9 +40,11 @@ HEADERS += \ Session/onlinesession.h \ clientdatacenter.h \ clientmain.h \ + codeeditor.h \ databaseoperation.h \ + myhighlighter.h \ + typedef.h \ userregister.cpp \ - highlighter.h \ kuang.h \ ltest.h \ mainwindow.h \ diff --git a/Client/codeeditor.cpp b/Client/codeeditor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30f668a46c5495c56c466394b1f0247b899028b7 --- /dev/null +++ b/Client/codeeditor.cpp @@ -0,0 +1,110 @@ +#include "codeeditor.h" +#include + +CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent) +{ + lineNumberArea = new LineNumberArea(this); + + connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); + connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); + connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); + + updateLineNumberAreaWidth(0); + setMode(BROWSE); +} +int CodeEditor::lineNumberAreaWidth() +{ + int digits = 1; + int max = qMax(1, blockCount()); + while (max >= 10) { + max /= 10; + ++digits; + } + + int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; + + return space; +} + +void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */) +{ + setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); +} + +void CodeEditor::updateLineNumberArea(const QRect &rect, int dy) +{ + if (dy) + lineNumberArea->scroll(0, dy); + else + lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); + + if (rect.contains(viewport()->rect())) + updateLineNumberAreaWidth(0); +} + +void CodeEditor::resizeEvent(QResizeEvent *e) +{ + QPlainTextEdit::resizeEvent(e); + + QRect cr = contentsRect(); + lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); +} +void CodeEditor::highlightCurrentLine() +{ + QList extraSelections; + + if (!isReadOnly()) { + QTextEdit::ExtraSelection selection; + + QColor lineColor = QColor(Qt::yellow).lighter(160); + + selection.format.setBackground(lineColor); + selection.format.setProperty(QTextFormat::FullWidthSelection, true); + //selection.cursor = textCursor(); + //selection.cursor.clearSelection(); + extraSelections.append(selection); + } + + setExtraSelections(extraSelections); +} + +void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) +{ + QPainter painter(lineNumberArea); + painter.fillRect(event->rect(), Qt::lightGray); + + + QTextBlock block = firstVisibleBlock(); + int blockNumber = block.blockNumber(); + int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top(); + int bottom = top + (int) blockBoundingRect(block).height(); + + while (block.isValid() && top <= event->rect().bottom()) { + if (block.isVisible() && bottom >= event->rect().top()) { + QString number = QString::number(blockNumber + 1); + painter.setPen(Qt::black); + painter.drawText(-2, top, lineNumberArea->width(), fontMetrics().height(), + Qt::AlignRight, number); + } + + block = block.next(); + top = bottom; + bottom = top + (int) blockBoundingRect(block).height(); + ++blockNumber; + } +} +void CodeEditor::setMode(editorMode mode) +{ + if(mode == BROWSE) + { + this->setReadOnly(true); + this->setStyleSheet("background:#f2f2f3;"); + highlightCurrentLine(); + } + else if(mode == EDIT) + { + this->setReadOnly(false); + this->setStyleSheet("background:#ffffff;"); + highlightCurrentLine(); + } +} diff --git a/Client/codeeditor.h b/Client/codeeditor.h new file mode 100644 index 0000000000000000000000000000000000000000..c6cf84e1e65392f882d1a98af0a760842afeeef9 --- /dev/null +++ b/Client/codeeditor.h @@ -0,0 +1,57 @@ +#ifndef CODEEDITOR_H +#define CODEEDITOR_H +#include +#include + +#include +#include +#include +#include +#include +#include +class LineNumberArea; + +class CodeEditor : public QPlainTextEdit +{ + Q_OBJECT + +public: + CodeEditor(QWidget *parent = 0); + void setMode(editorMode mode); + void lineNumberAreaPaintEvent(QPaintEvent *event); + int lineNumberAreaWidth(); + +protected: + void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; + +private slots: + void updateLineNumberAreaWidth(int newBlockCount); + void highlightCurrentLine(); + void updateLineNumberArea(const QRect &, int); + +private: + QWidget *lineNumberArea; +}; + + +class LineNumberArea : public QWidget +{ +public: + LineNumberArea(CodeEditor *editor) : QWidget(editor) { + codeEditor = editor; + } + + QSize sizeHint() const Q_DECL_OVERRIDE { + return QSize(codeEditor->lineNumberAreaWidth(), 0); + } + +protected: + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE { + codeEditor->lineNumberAreaPaintEvent(event); + } + +private: + CodeEditor *codeEditor; +}; + +#endif // CODEEDITOR_H diff --git a/Client/highlighter.h b/Client/highlighter.h deleted file mode 100644 index 493e59dd42389aa9b41f900a07eab081ebaae352..0000000000000000000000000000000000000000 --- a/Client/highlighter.h +++ /dev/null @@ -1,45 +0,0 @@ - -#ifndef HIGHLIGHTER_H -#define HIGHLIGHTER_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QTextDocument; -QT_END_NAMESPACE - -//! [0] -class Highlighter : public QSyntaxHighlighter //继承QSyntaxHightliaghter -{ - Q_OBJECT - -public: - Highlighter(QTextDocument *parent = 0);//构造函数传一个 QTextDocument 对象 给父类 - -protected: - void highlightBlock(const QString &text) override;//重写父类这个函数 自动调用 - -private: - - struct HighlightingRule//语法规则结构体,包含正则表达式模式串和匹配的样式 - { - QRegularExpression pattern; - QTextCharFormat format; - }; - QVector highlightingRules;//规则的集合,可以定义多个高亮规则 - - QRegularExpression commentStartExpression; //注释的高亮,使用highliangBlock()匹配,下文提到 - QRegularExpression commentEndExpression; - - QTextCharFormat keywordFormat;//高亮样式,关键词,一下顾名思义 - QTextCharFormat classFormat; - QTextCharFormat singleLineCommentFormat; - QTextCharFormat multiLineCommentFormat; - QTextCharFormat quotationFormat; - QTextCharFormat functionFormat; -}; -//! [0] - -#endif // HIGHLIGHTER_H diff --git a/Client/kuang.cpp b/Client/kuang.cpp index 85639565e064633db2f47a817bd1673e34518893..e054fea15c04a59b4e87da064e2e926536505322 100644 --- a/Client/kuang.cpp +++ b/Client/kuang.cpp @@ -27,6 +27,7 @@ Kuang::Kuang(const QString &username,QJsonObject data,QWidget *parent): ui->name->setText(temp[0].toObject()["Username"].toString()); } ui->profile->setPixmap(QPixmap(":/img/system/img/LittleRed.svg")); + } // GROUP diff --git a/Client/kuang.ui b/Client/kuang.ui index b09634e3ab8deff5817595f1ab157f8d6b4aef1d..1ccd57fc669c23e73b8e46e3fe48f8c6304e033a 100644 --- a/Client/kuang.ui +++ b/Client/kuang.ui @@ -22,41 +22,99 @@ 70 + + ArrowCursor + + + Qt::ClickFocus + Form + + false + + + QWidget::hover +{ + background-color::rgb(200,198,198); +} + - 10 + 20 10 50 50 + + QLabel +{ + background-color:transparent; +} + - QFrame::Box + QFrame::NoFrame profile + + true + - 70 - 15 + 80 + 10 161 - 41 + 21 + + + Microsoft YaHei + 14 + + + + QLabel +{ + background-color:transparent; +} + - QFrame::Box + QFrame::NoFrame name + + + + 0 + 0 + 253 + 70 + + + + QLabel::hover +{ + background-color:rgb(198,198,198); +} + + + + + + label + profile + name diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp index 3a307e34d9d57943ce2c25a42cd15bf9bbf32c51..e32c1ddf822c3f103c31b2fdb30270b8d41d11c2 100644 --- a/Client/mainwindow.cpp +++ b/Client/mainwindow.cpp @@ -15,14 +15,25 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); ui->tabWidget->setAttribute(Qt::WA_StyledBackground); -// QToolButton* btnSearch = new QToolButton; -// btnSearch->setCursor(Qt::PointingHandCursor);//如果不设置鼠标样式,鼠标移动到按钮上依旧显示为编辑框的鼠标样式 -// btnSearch->setIcon(QPixmap(":/img/system/img/search.png")); -// btnSearch->setIconSize(QSize(20,20)); -// btnSearch->setStyleSheet("QToolButton{border:none;}"); -// QWidgetAction* action = new QWidgetAction(ui->search); -// action->setDefaultWidget(btnSearch); -// ui->search->addAction(action, QLineEdit::TrailingPosition); + + QJsonObject data = {{ "MsgType", "SessionData" }, {"SessionID", 1}, {"SessionType", "FRIEND"} }; + QJsonArray members; + members.append(QJsonObject{{"Username", "小蓝"}}); + members.append(QJsonObject{{"Username", "xxx"}}); + data["Members"]=members; + Kuang *k = new Kuang("小蓝", data, this); + friendlayout = new QVBoxLayout(ui->frd); + friendlayout->setContentsMargins(0,0,0,0); + friendlayout->addWidget(k); + + QToolButton* btnSearch = new QToolButton; + btnSearch->setCursor(Qt::PointingHandCursor);//如果不设置鼠标样式,鼠标移动到按钮上依旧显示为编辑框的鼠标样式 + btnSearch->setIcon(QPixmap(":/img/system/img/search.png")); + btnSearch->setIconSize(QSize(20,20)); + btnSearch->setStyleSheet("QToolButton{border:none;}"); + QWidgetAction* action = new QWidgetAction(ui->search); + action->setDefaultWidget(btnSearch); + ui->search->addAction(action, QLineEdit::TrailingPosition); } MainWindow::~MainWindow() diff --git a/Client/mainwindow.ui b/Client/mainwindow.ui index 9e1370e24bd83e74deb17a440b7b0dca6c7771a1..b7b339b35ccb2d31e4a79c9514f11ef7a5344602 100644 --- a/Client/mainwindow.ui +++ b/Client/mainwindow.ui @@ -15,16 +15,13 @@ - :/img/system/img/bicq.png:/img/system/img/bicq.png + :/img/system/img/bicqGreen.png:/img/system/img/bicqGreen.png 1.000000000000000 - QMainWindow -{ - border-radius: 8px; -} + @@ -56,11 +53,11 @@ QTabWidget{ - background-color:rgb(46,46,46); + background-color:rgb(1,73,124); } QTabBar::tab { - background-color:rgb(46,46,46); + background-color:rgb(1,73,124); width:70px; height:70px; } @@ -78,7 +75,7 @@ QTabBar::tab:hover QTabWidget::Rounded - 1 + 0 @@ -108,7 +105,7 @@ QTabBar::tab:hover :/img/system/img/personalOff.png - :/img/system/img/personalOn.png + :/img/system/img/test.png @@ -248,7 +245,7 @@ QTabBar::tab:hover QFrame::NoFrame - nick name: + Nickname: @@ -276,7 +273,7 @@ QTabBar::tab:hover QFrame::NoFrame - user name: + Username: Qt::AutoText @@ -382,7 +379,7 @@ QLineEdit::focus :/system/system/img/message.png :/img/system/img/messageOff.png - :/img/system/img/messageOn.png:/system/system/img/message.png + :/img/system/img/messageOnFinal.png:/system/system/img/message.png @@ -430,101 +427,6 @@ QLineEdit::focus 0 - - - - - 370 - 30 - - - - - 16777215 - 30 - - - - QFrame::NoFrame - - - QFrame::Plain - - - - - 40 - 0 - 40 - 30 - - - - background-color: rgb(255, 255, 255); - - - - - - - :/img/system/img/git.png:/img/system/img/git.png - - - - 30 - 30 - - - - false - - - true - - - - - - 0 - 0 - 40 - 30 - - - - background-color: rgb(255, 255, 255); - - - - - - - :/img/system/img/face.png:/img/system/img/face.png - - - - 25 - 25 - - - - true - - - false - - - false - - - false - - - true - - - - @@ -551,23 +453,19 @@ QLineEdit::focus } QToolBox::tab { - background:rgb(245,245,245); + background:rgb(235,235,235); color:rgb(0,0,0); - border:1px solid black; - border-radius:5px; } QToolBox::tab::hover{ background:rgb(255,255,255); color:rgb(18,150,219); - border:1px solid black; - border-radius:5px; } - 1 + 2 - 1 + 0 @@ -594,7 +492,7 @@ QToolBox::tab::hover{ 0 0 253 - 540 + 543 @@ -607,7 +505,7 @@ QToolBox::tab::hover{ 0 0 253 - 540 + 543 @@ -616,47 +514,6 @@ QToolBox::tab::hover{ - - - - - 0 - 0 - - - - - 370 - 350 - - - - QListWidget -{ -background-color: rgb(245, 245, 245); -color:rgb(51,51,51); -border: 1px solid rgb(245, 245, 245); -outline:0px;} -QListWidget::Item{background-color: rgb(245, 245, 245);} -QListWidget::Item:hover{background-color: rgb(245, 245, 245); } -QListWidget::item:selected{ - background-color: rgb(245, 245, 245); - color:black; - border: 1px solid rgb(245, 245, 245); -} -QListWidget::item:selected:!active{border: 1px solid rgb(245, 245, 245); background-color: rgb(245, 245, 245); color:rgb(51,51,51); } - - - QFrame::NoFrame - - - Qt::ScrollBarAsNeeded - - - Qt::ScrollBarAlwaysOff - - - @@ -698,13 +555,28 @@ QListWidget::item:selected:!active{border: 1px solid rgb(245, 245, 245); backgr - 0 + 93 30 + + + 93 + 30 + + + + + Microsoft YaHei + 10 + + PointingHandCursor + + color: rgb(96,96,96); + send @@ -763,6 +635,148 @@ QListWidget::item:selected:!active{border: 1px solid rgb(245, 245, 245); backgr + + + + + 0 + 0 + + + + + 370 + 350 + + + + QListWidget +{ +background-color: rgb(245, 245, 245); +color:rgb(51,51,51); +border: 1px solid rgb(245, 245, 245); +outline:0px;} +QListWidget::Item{background-color: rgb(245, 245, 245);} +QListWidget::Item:hover{background-color: rgb(245, 245, 245); } +QListWidget::item:selected{ + background-color: rgb(245, 245, 245); + color:black; + border: 1px solid rgb(245, 245, 245); +} +QListWidget::item:selected:!active{border: 1px solid rgb(245, 245, 245); background-color: rgb(245, 245, 245); color:rgb(51,51,51); } + + + QFrame::NoFrame + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAlwaysOff + + + + + + + + 370 + 30 + + + + + 16777215 + 30 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + 40 + 0 + 40 + 30 + + + + PointingHandCursor + + + background-color: rgb(255, 255, 255); + + + + + + + :/img/system/img/git.png:/img/system/img/git.png + + + + 30 + 30 + + + + false + + + true + + + + + + 0 + 0 + 40 + 30 + + + + PointingHandCursor + + + background-color: rgb(255, 255, 255); + + + + + + + :/img/system/img/face.png:/img/system/img/face.png + + + + 25 + 25 + + + + false + + + false + + + false + + + false + + + true + + + + @@ -773,7 +787,7 @@ QListWidget::item:selected:!active{border: 1px solid rgb(245, 245, 245); backgr :/system/system/img/searchOff.png :/img/system/img/searchOff.png - :/img/system/img/searchOn.png:/system/system/img/searchOff.png + :/img/system/img/searchOnFinal.png:/system/system/img/searchOff.png @@ -924,7 +938,7 @@ QLineEdit::focus - 用户名或昵称或群聊ID + 用户名或昵称 @@ -949,7 +963,7 @@ QLineEdit::focus :/system/system/img/addOff.png :/img/system/img/addOff.png - :/img/system/img/addOn.png:/system/system/img/addOff.png + :/img/system/img/addOnFinal.png:/system/system/img/addOff.png @@ -1040,7 +1054,7 @@ QLineEdit::focus :/img/system/img/gitOff.png - :/img/system/img/gitOn.png + :/img/system/img/gitOnFinal.png diff --git a/Client/highlighter.cpp b/Client/myhighlighter.cpp similarity index 39% rename from Client/highlighter.cpp rename to Client/myhighlighter.cpp index bcdd88121f8f04b9b7e6524b62435aa90ebf3293..6a997a954a2dee07ad7957fc355f7aa894aadd60 100644 --- a/Client/highlighter.cpp +++ b/Client/myhighlighter.cpp @@ -1,14 +1,13 @@ -#include "highlighter.h" +#include "myhighlighter.h" -//! [0] -Highlighter::Highlighter(QTextDocument *parent) +MyHighLighter::MyHighLighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { HighlightingRule rule; - keywordFormat.setForeground(Qt::red);//设定关键词的高亮样式 + keywordFormat.setForeground(Qt::darkBlue); keywordFormat.setFontWeight(QFont::Bold); - QStringList keywordPatterns; //关键词集合,关键都以正则表达式表示 下面的可以改为我们想要的关键词 + QStringList keywordPatterns; keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b" << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b" << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b" @@ -18,91 +17,75 @@ Highlighter::Highlighter(QTextDocument *parent) << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b" << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b" << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b" - << "\\bvoid\\b" << "\\bvolatile\\b" << "\\bbool\\b" - << "\\bdef\\b"<< "\\binclude\\b"<< "\\bself\\b"<< "\\btype\\b" - << "\\bimport\\b"<< "\\bfrom\\b"<< "\\bbreak\\b"<< "\\band\\b"<< "\\bor\\b" - << "\\bif\\b"<< "\\btry\\b"<< "\\bexcept\\b"<< "\\bNone\\b"<< "\\bwith\\b" - << "\\bencoding\\b"<< "\\breturn\\b"<< "\\bnot\\b"<< "\\belif\\b"<< "\\belse\\b"; + << "\\bvoid\\b" << "\\bvolatile\\b" <<"\\bdef\\b" + << "\\binclude\\b" << "\\breturn\\b" <<"\\bbreak\\b" + << "\\bcontinue\\b" << "\\bif\\b" <<"\\belse\\b" + << "\\belif\\b" << "\\band\\b" <<"\\bTrue\\b" + << "\\bself\\b" << "\\bnn\\b" <<"\\bimport\\b" + << "\\bin\\b" << "\\bfor\\b" <<"\\bis\\b"; foreach (const QString &pattern, keywordPatterns) { - rule.pattern = QRegularExpression(pattern); + rule.pattern = QRegExp(pattern); rule.format = keywordFormat; highlightingRules.append(rule); -//! [0] //! [1] } -//! [1] - -//! [2] - classFormat.setFontWeight(QFont::Bold);//添加Qt的类到高亮规则中 + classFormat.setFontWeight(QFont::Bold); classFormat.setForeground(Qt::darkMagenta); - rule.pattern = QRegularExpression("\\bQ[A-Za-z]+\\b"); + rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b"); rule.format = classFormat; highlightingRules.append(rule); -//! [2] -//! [3] - singleLineCommentFormat.setForeground(Qt::darkBlue);//单行注释 - rule.pattern = QRegularExpression("//[^\n]*"); + singleLineCommentFormat.setForeground(Qt::red); + rule.pattern = QRegExp("//[^\n]*"); rule.format = singleLineCommentFormat; highlightingRules.append(rule); - multiLineCommentFormat.setForeground(Qt::darkBlue);//多行注释,只设定了样式,具体匹配在highlightBlock中设置 -//! [3] + multiLineCommentFormat.setForeground(Qt::red); -//! [4] - quotationFormat.setForeground(Qt::darkGreen);//字符串 - rule.pattern = QRegularExpression("\".*\""); + quotationFormat.setForeground(Qt::darkGreen); + rule.pattern = QRegExp("\".*\""); rule.format = quotationFormat; highlightingRules.append(rule); -//! [4] -//! [5] - functionFormat.setFontItalic(true);//函数 + functionFormat.setFontItalic(true); functionFormat.setForeground(Qt::blue); - rule.pattern = QRegularExpression("\\b[A-Za-z0-9_]+(?=\\()"); + rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()"); rule.format = functionFormat; highlightingRules.append(rule); -//! [5] -//! [6] - commentStartExpression = QRegularExpression("/\\*");//多行注释的匹配正则表达式 - commentEndExpression = QRegularExpression("\\*/"); + commentStartExpression = QRegExp("/\\*"); + commentEndExpression = QRegExp("\\*/"); } -//! [6] -//! [7] -void Highlighter::highlightBlock(const QString &text)//应用高亮规则,也用于区块的高亮,比如多行注释 +void MyHighLighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) {//文本采用高亮规则 - QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); - while (matchIterator.hasNext()) { - QRegularExpressionMatch match = matchIterator.next(); - setFormat(match.capturedStart(), match.capturedLength(), rule.format); + foreach (const HighlightingRule &rule, highlightingRules) { + QRegExp expression(rule.pattern); + int index = expression.indexIn(text); + while (index >= 0) { + int length = expression.matchedLength(); + setFormat(index, length, rule.format); + index = expression.indexIn(text, index + length); } } -//! [7] //! [8] - setCurrentBlockState(0); //以下是多行注释的匹配 -//! [8] -//! [9] + setCurrentBlockState(0); + int startIndex = 0; if (previousBlockState() != 1) - startIndex = text.indexOf(commentStartExpression); + startIndex = commentStartExpression.indexIn(text); + -//! [9] //! [10] while (startIndex >= 0) { -//! [10] //! [11] - QRegularExpressionMatch match = commentEndExpression.match(text, startIndex); - int endIndex = match.capturedStart(); - int commentLength = 0; + int endIndex = commentEndExpression.indexIn(text, startIndex); + int commentLength; if (endIndex == -1) { setCurrentBlockState(1); commentLength = text.length() - startIndex; } else { commentLength = endIndex - startIndex - + match.capturedLength(); + + commentEndExpression.matchedLength(); } setFormat(startIndex, commentLength, multiLineCommentFormat); - startIndex = text.indexOf(commentStartExpression, startIndex + commentLength); + startIndex = commentStartExpression.indexIn(text, startIndex + commentLength); } } -//! [11] diff --git a/Client/myhighlighter.h b/Client/myhighlighter.h new file mode 100644 index 0000000000000000000000000000000000000000..edd2c7acff24ab2f830b9302588bb1a715834025 --- /dev/null +++ b/Client/myhighlighter.h @@ -0,0 +1,36 @@ +#ifndef MYHIGHLIGHTER_H +#define MYHIGHLIGHTER_H +#include +#include +#include +class MyHighLighter : public QSyntaxHighlighter +{ + Q_OBJECT + +public: + MyHighLighter(QTextDocument *parent = 0); + +protected: + void highlightBlock(const QString &text) Q_DECL_OVERRIDE; + +private: + struct HighlightingRule + { + QRegExp pattern; + QTextCharFormat format; + }; + QVector highlightingRules; + + QRegExp commentStartExpression; + QRegExp commentEndExpression; + + QTextCharFormat keywordFormat; + QTextCharFormat classFormat; + QTextCharFormat singleLineKey; + QTextCharFormat singleLineValue; + QTextCharFormat singleLineCommentFormat; + QTextCharFormat multiLineCommentFormat; + QTextCharFormat quotationFormat; + QTextCharFormat functionFormat; +}; +#endif // MYHIGHLIGHTER_H diff --git a/Client/system.qrc b/Client/system.qrc index 286d58d92ad9682d8c382cd5298dae7f3deb84ff..97afe8bee04ecdfbe01bd853a694a28c78a44b06 100644 --- a/Client/system.qrc +++ b/Client/system.qrc @@ -22,5 +22,14 @@ system/img/LittlePink.svg system/img/LittleRed.svg system/img/bicqWhite.png + system/img/gitWhite.png + system/img/test.png + system/img/bicqBlue.png + system/img/bicqGreen.png + system/img/dot.png + system/img/addOnFinal.png + system/img/gitOnFinal.png + system/img/messageOnFinal.png + system/img/searchOnFinal.png diff --git a/Client/system/img/addOnFinal.png b/Client/system/img/addOnFinal.png new file mode 100644 index 0000000000000000000000000000000000000000..cc83baf29100e997df66e5120b5b52891d3d3f6d Binary files /dev/null and b/Client/system/img/addOnFinal.png differ diff --git a/Client/system/img/bicqBlue.png b/Client/system/img/bicqBlue.png new file mode 100644 index 0000000000000000000000000000000000000000..9ce6ec252f5827ebb95597ff3eaeda6f75dbbad4 Binary files /dev/null and b/Client/system/img/bicqBlue.png differ diff --git a/Client/system/img/bicqGreen.png b/Client/system/img/bicqGreen.png new file mode 100644 index 0000000000000000000000000000000000000000..b397cf3973590bbbf4db818ab89ac263718e64f4 Binary files /dev/null and b/Client/system/img/bicqGreen.png differ diff --git a/Client/system/img/dot.png b/Client/system/img/dot.png new file mode 100644 index 0000000000000000000000000000000000000000..b68fe73d89f5c3f6b59139dde5f56e047c195fe5 Binary files /dev/null and b/Client/system/img/dot.png differ diff --git a/Client/system/img/gitOnFinal.png b/Client/system/img/gitOnFinal.png new file mode 100644 index 0000000000000000000000000000000000000000..19befd4892b87be487f278b5384884d2000086cc Binary files /dev/null and b/Client/system/img/gitOnFinal.png differ diff --git a/Client/system/img/gitWhite.png b/Client/system/img/gitWhite.png new file mode 100644 index 0000000000000000000000000000000000000000..e0851f766146608826f56de946a62fe43c053c25 Binary files /dev/null and b/Client/system/img/gitWhite.png differ diff --git a/Client/system/img/messageOnFinal.png b/Client/system/img/messageOnFinal.png new file mode 100644 index 0000000000000000000000000000000000000000..6915ce31f1f304421d841dda5dc5dedeb02c1a41 Binary files /dev/null and b/Client/system/img/messageOnFinal.png differ diff --git a/Client/system/img/searchOnFinal.png b/Client/system/img/searchOnFinal.png new file mode 100644 index 0000000000000000000000000000000000000000..c0318459e7a69404a89f2ed137e0ebb78c8d73ed Binary files /dev/null and b/Client/system/img/searchOnFinal.png differ diff --git a/Client/system/img/test.png b/Client/system/img/test.png new file mode 100644 index 0000000000000000000000000000000000000000..560ecc55412835dd6a3142ed498017745391552f Binary files /dev/null and b/Client/system/img/test.png differ diff --git a/Client/typedef.h b/Client/typedef.h new file mode 100644 index 0000000000000000000000000000000000000000..499a81de8b6ce134d796e5ac8edf652ecfe7b9b6 --- /dev/null +++ b/Client/typedef.h @@ -0,0 +1,10 @@ +#ifndef TYPEDEF_H +#define TYPEDEF_H + +typedef enum{ + BROWSE, + EDIT, +}editorMode; + + +#endif // TYPEDEF_H diff --git a/Client/userlogin.cpp b/Client/userlogin.cpp index 51a97b9186414bf8996d1fa91cb77d7a19f519e0..7eab7d00431457852165da2bc91220a77d8c1cc6 100644 --- a/Client/userlogin.cpp +++ b/Client/userlogin.cpp @@ -23,7 +23,7 @@ UserLogin::UserLogin(QWidget *parent) this->hide(); emit registerButtonClicked(); }); - +#define UIDEBUG #ifndef UIDEBUG //点击登录发送登录信息 connect(ui->btnLogIn,&QPushButton::clicked,[=](){ diff --git a/Client/userlogin.ui b/Client/userlogin.ui index 0e4a538f244ef28ba221136d6d73030bcb8e8ffd..4da7a6ec3ecc9cf8cfe8084a5c0cd32fa4a5b23b 100644 --- a/Client/userlogin.ui +++ b/Client/userlogin.ui @@ -27,7 +27,7 @@ - :/img/system/img/bicq.png:/img/system/img/bicq.png + :/img/system/img/bicqGreen.png:/img/system/img/bicqGreen.png @@ -39,7 +39,7 @@ 165 - 30 + 50 100 100 @@ -148,7 +148,7 @@ QPushButton::hover{ - Usesrname + Username @@ -302,7 +302,7 @@ QPushButton::hover{ } - Sign in + Sign In @@ -316,7 +316,7 @@ QPushButton::hover{ 110 - 150 + 170 201 51 @@ -334,7 +334,7 @@ QPushButton::hover{ } - Sign in to BICQ + Sign In to BICQ diff --git a/Client/userregister.ui b/Client/userregister.ui index 7e0bb34e187c0284e332f7cde52d3b428df427f9..dbaabbfd7bbecade2b035ce55ca8f35d320c2ac0 100644 --- a/Client/userregister.ui +++ b/Client/userregister.ui @@ -23,14 +23,14 @@ - Form + UserRegister - :/img/system/img/bicq.png:/img/system/img/bicq.png + :/img/system/img/bicqGreen.png:/img/system/img/bicqGreen.png - background-color: rgb(255, 255, 255); + @@ -64,7 +64,7 @@ - Usesrname + Username @@ -305,14 +305,14 @@ QPushButton::hover{ } - Sign in + Sign Up - 165 - 30 + 50 + 60 100 100 @@ -330,9 +330,9 @@ QPushButton::hover{ - 110 - 150 - 211 + 160 + 50 + 231 51 @@ -349,7 +349,145 @@ QPushButton::hover{ } - Sign up to BICQ + Sign Up to + + + + + + 163 + 103 + 20 + 20 + + + + + 20 + 20 + + + + + 10 + 10 + + + + QLabel +{ + background-color:transparent; +} + + + + + + :/img/system/img/dot.png + + + true + + + + + + 174 + 96 + 20 + 20 + + + + + 20 + 20 + + + + + 10 + 10 + + + + QLabel +{ + background-color:transparent; +} + + + + + + :/img/system/img/dot.png + + + true + + + + + + 150 + 106 + 20 + 20 + + + + + 20 + 20 + + + + + 10 + 10 + + + + QLabel +{ + background-color:transparent; +} + + + + + + :/img/system/img/dot.png + + + true + + + + + + 303 + 46 + 101 + 51 + + + + + Microsoft YaHei + 20 + 75 + true + + + + QLabel +{ + color: rgb(18,150,219); +} + + + BICQ diff --git a/Client/widget.cpp b/Client/widget.cpp index 58453cdcd57c5bc218c2758cc7f9088e6cdca588..6a5bfa63dc269662cf33af6b596ec90a1327ca75 100644 --- a/Client/widget.cpp +++ b/Client/widget.cpp @@ -1,34 +1,38 @@ #include "widget.h" #include "ui_widget.h" -#include "highlighter.h" -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include "myhighlighter.h" +#include "codeeditor.h" +#include "typedef.h" +#include Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); - + configEditor = new CodeEditor(); + configEditor->setMode(BROWSE); + ui->gridLayout_3->addWidget(configEditor); connect (ui->listWidget, &QListWidget::itemDoubleClicked, this, &Widget::showContents); } Widget::~Widget() { delete ui; + } void Widget::on_pushButton_clicked() { - QString giturl = "https://gitee.com/api/v5/repos/" + ui->lineEdit->text() + "/" + - ui->lineEdit_2->text() + "/git/trees/master"; - QByteArray file = get(giturl); + QByteArray file = get(ui->lineEdit->text ()); QJsonDocument newjson = QJsonDocument::fromJson(file); QJsonObject jsonObject = newjson.object (); @@ -60,14 +64,20 @@ void Widget::showContents(QListWidgetItem * nowItem) { QJsonValue iconArray = array.at(i); QJsonObject icon = iconArray.toObject(); + if(icon["path"].toString ()==nowItem->text ()) { QByteArray content = get(icon["url"].toString ()); QJsonDocument newjson = QJsonDocument::fromJson(content); QJsonObject jsonObject = newjson.object (); - ui->textEdit->setText ( QByteArray::fromBase64(jsonObject["content"].toString ().toUtf8 ())); - Highlighter * h = new Highlighter(ui->textEdit->document ()); + configEditor->setPlainText(QByteArray::fromBase64(jsonObject["content"].toString ().toUtf8 ()).data ()); + //ui->gridLayout->addWidget(configEditor); + QString text = "def hhh()"; + MyHighLighter *highlighter = new MyHighLighter(configEditor->document()); + + //Highlighter * h = new Highlighter(ui->textEdit->document ()); + } } @@ -77,7 +87,6 @@ void Widget::showContents(QListWidgetItem * nowItem) // git commit try at: https://gitee.com/api/v5/repos/jasonliu233/gitstudy/commits/master // git tree at: https://gitee.com/api/v5/repos/jasonliu233/zhishigongcheng/git/trees/master - int captureGitRepo(QString raw, QList &authors, QList &repos, QList &commits) { QRegExp reg("@\\[((?:[^ ,\\,])+),[ ]*((?:[^ ,\\,])+)(?:,[ ]*((?:[^ ,\\,])*))?\\]"); int pos = 0, initial = authors.size(); diff --git a/Client/widget.h b/Client/widget.h index 201451bc28cf811eba04d0e47a71ea89ca033dbf..0e1b5efde6594039b9feac18c49802bb46d3e1a8 100644 --- a/Client/widget.h +++ b/Client/widget.h @@ -7,6 +7,8 @@ #include #include #include +#include + QT_BEGIN_NAMESPACE namespace Ui { class Widget; } @@ -42,11 +44,10 @@ private slots: private: Ui::Widget *ui; QJsonValue arrayValue; + CodeEditor *configEditor; }; + int captureGitRepo(QString raw, QList &authors, QList &repos, QList &commits); QString generateGitMessage(QString owner, QString repo, QString sha); -QByteArray get(const QString &str_url); - #endif // WIDGET_H - diff --git a/Client/widget.ui b/Client/widget.ui index 0ea2faa3d57551204036f9e444f1a25b2c3140a9..9613d09c320990752c733a91e57dc5f7e076359b 100644 --- a/Client/widget.ui +++ b/Client/widget.ui @@ -107,17 +107,28 @@ QLineEdit::focus 80 + + PointingHandCursor + - background-color: rgb(46,46,46); + QPushButton{ + border:1px solid rgb(55,63,85); + border-radius: 10px; + background-color:rgb(22,138,173); +} +QPushButton::hover{ + + border:1px solid rgb(55,63,85); + border-radius: 10px; + background-color:rgb(18,150,219); +} - - :/img/system/img/gitBtnOff.png - :/img/system/img/gitBtnOn.png - + + :/img/system/img/gitWhite.png:/img/system/img/gitWhite.png @@ -214,22 +225,6 @@ border-style: solid; - - - - - Microsoft Yi Baiti - 12 - - - - background-color: rgb(245, 245, 245); - - - QFrame::NoFrame - - - @@ -279,8 +274,17 @@ border-style: solid; + + + + 0 + + + - + + +