- add: "C Reference" in the help menu

- fix: Custom editor colors shouldn't be tested for high contrast with the default background color
 - fix: Custom color settings not correctly displayed in the options widget
 - enhancement: add hit counts in the search result view
 - fix: editor actions' state not correctly updated after close editors.
This commit is contained in:
royqh1979 2021-11-02 23:47:51 +08:00
parent 34bdd7815f
commit d297faf3af
16 changed files with 457 additions and 392 deletions

View File

@ -3,6 +3,11 @@ Version 0.7.8
- fix: current input/expected not correctly applied when save/run problem cases - fix: current input/expected not correctly applied when save/run problem cases
- fix: colors of the syntax issues view are not correctly set using the current color sheme - fix: colors of the syntax issues view are not correctly set using the current color sheme
- change: The error color of color scheme "vs code" - change: The error color of color scheme "vs code"
- add: "C Reference" in the help menu
- fix: Custom editor colors shouldn't be tested for high contrast with the default background color
- fix: Custom color settings not correctly displayed in the options widget
- enhancement: add hit counts in the search result view
- fix: editor actions' state not correctly updated after close editors.
Version 0.7.7 Version 0.7.7
- enhancement: Problem Set - enhancement: Problem Set

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,9 @@
EditorList::EditorList(QTabWidget* leftPageWidget, EditorList::EditorList(QTabWidget* leftPageWidget,
QTabWidget* rightPageWidget, QTabWidget* rightPageWidget,
QSplitter* splitter, QSplitter* splitter,
QWidget* panel): QWidget* panel,
QObject* parent):
QObject(parent),
mLayout(LayoutShowType::lstLeft), mLayout(LayoutShowType::lstLeft),
mLeftPageWidget(leftPageWidget), mLeftPageWidget(leftPageWidget),
mRightPageWidget(rightPageWidget), mRightPageWidget(rightPageWidget),
@ -157,9 +159,7 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
else else
pMainWindow->updateClassBrowserForEditor(editor); pMainWindow->updateClassBrowserForEditor(editor);
} }
if (pageCount()==0) { emit editorClosed();
pMainWindow->updateAppTitle();
}
return true; return true;
} }
@ -290,7 +290,6 @@ bool EditorList::closeAll(bool force) {
return false; return false;
} }
} }
pMainWindow->updateAppTitle();
return true; return true;
} }
@ -301,6 +300,7 @@ void EditorList::forceCloseEditor(Editor *editor)
// Force layout update when creating, destroying or moving editors // Force layout update when creating, destroying or moving editors
updateLayout(); updateLayout();
endUpdate(); endUpdate();
emit editorClosed();
} }
Editor* EditorList::getOpenedEditorByFilename(QString filename) Editor* EditorList::getOpenedEditorByFilename(QString filename)

View File

@ -7,8 +7,9 @@
#include "utils.h" #include "utils.h"
class Editor; class Editor;
class EditorList class EditorList : public QObject
{ {
Q_OBJECT
public: public:
enum class LayoutShowType{ enum class LayoutShowType{
lstLeft, lstLeft,
@ -19,7 +20,7 @@ public:
explicit EditorList(QTabWidget* leftPageWidget, explicit EditorList(QTabWidget* leftPageWidget,
QTabWidget* rightPageWidget, QTabWidget* rightPageWidget,
QSplitter* splitter, QSplitter* splitter,
QWidget* panel); QWidget* panel, QObject* parent = nullptr);
Editor* newEditor(const QString& filename, const QByteArray& encoding, Editor* newEditor(const QString& filename, const QByteArray& encoding,
bool inProject, bool newFile, bool inProject, bool newFile,
@ -59,6 +60,9 @@ public:
QTabWidget *rightPageWidget() const; QTabWidget *rightPageWidget() const;
signals:
void editorClosed();
private: private:
QTabWidget* getNewEditorPageControl() const; QTabWidget* getNewEditorPageControl() const;
QTabWidget* getFocusedPageControl() const; QTabWidget* getFocusedPageControl() const;

View File

@ -76,6 +76,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->EditorTabsRight, ui->EditorTabsRight,
ui->splitterEditorPanel, ui->splitterEditorPanel,
ui->EditorPanel); ui->EditorPanel);
connect(mEditorList, &EditorList::editorClosed,
this, &MainWindow::onEditorClosed);
mProject = nullptr; mProject = nullptr;
setupActions(); setupActions();
ui->EditorTabsRight->setVisible(false); ui->EditorTabsRight->setVisible(false);
@ -447,11 +449,6 @@ void MainWindow::updateCompileActions()
|| mEditorList->pageCount()>0); || mEditorList->pageCount()>0);
} }
static bool haveGoodContrast(const QColor& c1, const QColor &c2) {
int lightness1 = c1.lightness();
int lightness2 = c2.lightness();
return std::abs(lightness1 - lightness2)>=100;
}
void MainWindow::updateEditorColorSchemes() void MainWindow::updateEditorColorSchemes()
{ {
@ -466,50 +463,54 @@ void MainWindow::updateEditorColorSchemes()
item = pColorManager->getItem(schemeName, SYNS_AttrFunction); item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
QColor baseColor = palette().color(QPalette::Base); QColor baseColor = palette().color(QPalette::Base);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skFunction,item); mStatementColors->insert(StatementKind::skFunction,item);
mStatementColors->insert(StatementKind::skConstructor,item); mStatementColors->insert(StatementKind::skConstructor,item);
mStatementColors->insert(StatementKind::skDestructor,item); mStatementColors->insert(StatementKind::skDestructor,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrClass); item = pColorManager->getItem(schemeName, SYNS_AttrClass);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skClass,item); mStatementColors->insert(StatementKind::skClass,item);
mStatementColors->insert(StatementKind::skTypedef,item); mStatementColors->insert(StatementKind::skTypedef,item);
mStatementColors->insert(StatementKind::skAlias,item); mStatementColors->insert(StatementKind::skAlias,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier); item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skEnumType,item); mStatementColors->insert(StatementKind::skEnumType,item);
mStatementColors->insert(StatementKind::skEnumClassType,item); mStatementColors->insert(StatementKind::skEnumClassType,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrVariable); item = pColorManager->getItem(schemeName, SYNS_AttrVariable);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skVariable,item); mStatementColors->insert(StatementKind::skVariable,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable); item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skLocalVariable,item); mStatementColors->insert(StatementKind::skLocalVariable,item);
mStatementColors->insert(StatementKind::skParameter,item); mStatementColors->insert(StatementKind::skParameter,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable); item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skGlobalVariable,item); mStatementColors->insert(StatementKind::skGlobalVariable,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor); item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skPreprocessor,item); mStatementColors->insert(StatementKind::skPreprocessor,item);
mStatementColors->insert(StatementKind::skEnum,item); mStatementColors->insert(StatementKind::skEnum,item);
if (haveGoodContrast(item->foreground(), baseColor)) {
mHeaderCompletionPopup->setSuggestionColor(item->foreground()); mHeaderCompletionPopup->setSuggestionColor(item->foreground());
} else { } else {
mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text)); mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text));
} }
} else {
mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text));
}
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord); item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skKeyword,item); mStatementColors->insert(StatementKind::skKeyword,item);
mStatementColors->insert(StatementKind::skUserCodeSnippet,item); mStatementColors->insert(StatementKind::skUserCodeSnippet,item);
} }
item = pColorManager->getItem(schemeName, SYNS_AttrString); item = pColorManager->getItem(schemeName, SYNS_AttrString);
if (item && haveGoodContrast(item->foreground(), baseColor)) { if (item) {
mStatementColors->insert(StatementKind::skNamespace,item); mStatementColors->insert(StatementKind::skNamespace,item);
mStatementColors->insert(StatementKind::skNamespaceAlias,item); mStatementColors->insert(StatementKind::skNamespaceAlias,item);
} }
@ -1119,7 +1120,7 @@ bool MainWindow::compile(bool rebuild)
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor != NULL ) {
clearIssues(); clearIssues();
if (editor->modified()) { if (editor->modified() || editor->isNew()) {
if (!editor->save(false,false)) if (!editor->save(false,false))
return false; return false;
} }
@ -1210,7 +1211,7 @@ void MainWindow::runExecutable(RunType runType)
} else { } else {
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor != NULL ) { if (editor != NULL ) {
if (editor->modified()) { if (editor->modified() || editor->isNew()) {
if (!editor->save(false,false)) if (!editor->save(false,false))
return; return;
} }
@ -1342,13 +1343,12 @@ void MainWindow::debug()
Editor* e = mEditorList->getEditor(); Editor* e = mEditorList->getEditor();
if (e!=nullptr) { if (e!=nullptr) {
// Did we saved? // Did we saved?
if (e->modified()) { if (e->modified() || e->isNew()) {
// if file is modified,save it first // if file is modified,save it first
if (!e->save(false,false)) if (!e->save(false,false))
return; return;
} }
// Did we compiled? // Did we compiled?
filePath = getCompiledExecutableName(e->filename()); filePath = getCompiledExecutableName(e->filename());
debugFile.setFile(filePath); debugFile.setFile(filePath);
@ -1386,7 +1386,9 @@ void MainWindow::debug()
} }
break; break;
default: default:
break; //don't compile
updateEditorActions();
return;
} }
updateEditorActions(); updateEditorActions();
@ -2673,6 +2675,14 @@ void MainWindow::onNewProblemConnection()
clientConnection->disconnectFromHost(); clientConnection->disconnectFromHost();
} }
void MainWindow::onEditorClosed()
{
if (mQuitting)
return;
updateEditorActions();
updateAppTitle();
}
void MainWindow::onShowInsertCodeSnippetMenu() void MainWindow::onShowInsertCodeSnippetMenu()
{ {
mMenuInsertCodeSnippet->clear(); mMenuInsertCodeSnippet->clear();
@ -5200,3 +5210,22 @@ void MainWindow::on_btnRunAllProblemCases_clicked()
runExecutable(RunType::ProblemCases); runExecutable(RunType::ProblemCases);
} }
void MainWindow::on_actionC_Reference_triggered()
{
if (pSettings->environment().language()=="zh_CN") {
QDesktopServices::openUrl(QUrl("https://zh.cppreference.com/w/c"));
} else {
QDesktopServices::openUrl(QUrl("https://en.cppreference.com/w/c"));
}
}
void MainWindow::on_btnRemoveProblemCase_clicked()
{
QModelIndex idx = ui->lstProblemCases->currentIndex();
if (idx.isValid()) {
mOJProblemModel.removeCase(idx.row());
}
}

View File

@ -231,6 +231,7 @@ private slots:
void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous); void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void onProblemNameChanged(int index); void onProblemNameChanged(int index);
void onNewProblemConnection(); void onNewProblemConnection();
void onEditorClosed();
void onShowInsertCodeSnippetMenu(); void onShowInsertCodeSnippetMenu();
@ -467,6 +468,10 @@ private slots:
void on_btnRunAllProblemCases_clicked(); void on_btnRunAllProblemCases_clicked();
void on_actionC_Reference_triggered();
void on_btnRemoveProblemCase_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
EditorList *mEditorList; EditorList *mEditorList;

View File

@ -497,7 +497,7 @@
<enum>QTabWidget::South</enum> <enum>QTabWidget::South</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>6</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -1460,6 +1460,7 @@
<property name="title"> <property name="title">
<string>Help</string> <string>Help</string>
</property> </property>
<addaction name="actionC_Reference"/>
<addaction name="actionC_C_Reference"/> <addaction name="actionC_C_Reference"/>
<addaction name="actionEGE_Manual"/> <addaction name="actionEGE_Manual"/>
<addaction name="actionAbout"/> <addaction name="actionAbout"/>
@ -2350,7 +2351,10 @@
</action> </action>
<action name="actionC_C_Reference"> <action name="actionC_C_Reference">
<property name="text"> <property name="text">
<string>C/C++ Reference</string> <string>C++ Reference</string>
</property>
<property name="toolTip">
<string>C++ Reference</string>
</property> </property>
</action> </action>
<action name="actionEGE_Manual"> <action name="actionEGE_Manual">
@ -2408,6 +2412,11 @@
<string>Running Parameters...</string> <string>Running Parameters...</string>
</property> </property>
</action> </action>
<action name="actionC_Reference">
<property name="text">
<string>C Reference</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -3,7 +3,7 @@
#include <QStringList> #include <QStringList>
#define DEVCPP_VERSION "0.7.7" #define DEVCPP_VERSION "0.7.8"
#define APP_SETTSINGS_FILENAME "redpandacpp.ini" #define APP_SETTSINGS_FILENAME "redpandacpp.ini"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

View File

@ -852,3 +852,9 @@ QByteArray getHTTPBody(const QByteArray& content) {
} }
return ""; return "";
} }
bool haveGoodContrast(const QColor& c1, const QColor &c2) {
int lightness1 = c1.lightness();
int lightness2 = c2.lightness();
return std::abs(lightness1 - lightness2)>=80;
}

View File

@ -167,6 +167,7 @@ QString TrimLeft(const QString& s);
bool StringIsBlank(const QString& s); bool StringIsBlank(const QString& s);
int compareFileModifiedTime(const QString& filename1, const QString& filename2); int compareFileModifiedTime(const QString& filename1, const QString& filename2);
QByteArray getHTTPBody(const QByteArray& content); QByteArray getHTTPBody(const QByteArray& content);
bool haveGoodContrast(const QColor& c1, const QColor &c2);
//void changeTheme(const QString& themeName); //void changeTheme(const QString& themeName);

View File

@ -6,6 +6,7 @@
#include "../mainwindow.h" #include "../mainwindow.h"
#include "../settings.h" #include "../settings.h"
#include "../colorscheme.h" #include "../colorscheme.h"
#include "../utils.h"
ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent) ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent)
{ {
@ -140,8 +141,10 @@ QVariant ClassBrowserModel::data(const QModelIndex &index, int role) const
kind = StatementKind::skPreprocessor; kind = StatementKind::skPreprocessor;
} }
PColorSchemeItem item = mColors->value(kind,PColorSchemeItem()); PColorSchemeItem item = mColors->value(kind,PColorSchemeItem());
if (item) { if (item && haveGoodContrast(item->foreground(), pMainWindow->palette().color(QPalette::Base))) {
return item->foreground(); return item->foreground();
} else {
return QVariant();
} }
} }
return pMainWindow->palette().color(QPalette::Text); return pMainWindow->palette().color(QPalette::Text);

View File

@ -25,7 +25,7 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) :
kind = statement->kind; kind = statement->kind;
} }
PColorSchemeItem item = mColors->value(kind,PColorSchemeItem()); PColorSchemeItem item = mColors->value(kind,PColorSchemeItem());
if (item) { if (item && haveGoodContrast(item->foreground(),palette().color(QPalette::Base))) {
return item->foreground(); return item->foreground();
} }
return palette().color(QPalette::Text); return palette().color(QPalette::Text);

View File

@ -23,7 +23,7 @@ void ColorEdit::setColor(const QColor &value)
mColor=value; mColor=value;
emit colorChanged(value); emit colorChanged(value);
resize(sizeHint()); resize(sizeHint());
// update(); repaint();
} }
} }

View File

@ -236,6 +236,8 @@ bool HeaderCompletionPopup::event(QEvent *event)
case QEvent::FontChange: case QEvent::FontChange:
mListView->setFont(font()); mListView->setFont(font());
break; break;
default:
break;
} }
return result; return result;
} }

View File

@ -150,7 +150,7 @@ void OJProblemSetModel::loadFromFile(const QString &fileName)
} }
} }
int OJProblemSetModel::rowCount(const QModelIndex &parent) const int OJProblemSetModel::rowCount(const QModelIndex &) const
{ {
return mProblemSet.problems.count(); return mProblemSet.problems.count();
} }

View File

@ -208,7 +208,8 @@ QVariant SearchResultTreeModel::data(const QModelIndex &index, int role) const
} }
if (item->parent==nullptr) { //is filename if (item->parent==nullptr) { //is filename
return item->filename; return QString("%1(%2)").arg(item->filename)
.arg(item->results.count());
} else { } else {
return QString("%1 %2: %3").arg(tr("Line")).arg(item->line) return QString("%1 %2: %3").arg(tr("Line")).arg(item->line)
.arg(item->text); .arg(item->text);