- 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: colors of the syntax issues view are not correctly set using the current color sheme
- 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
- enhancement: Problem Set

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -76,6 +76,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->EditorTabsRight,
ui->splitterEditorPanel,
ui->EditorPanel);
connect(mEditorList, &EditorList::editorClosed,
this, &MainWindow::onEditorClosed);
mProject = nullptr;
setupActions();
ui->EditorTabsRight->setVisible(false);
@ -447,11 +449,6 @@ void MainWindow::updateCompileActions()
|| 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()
{
@ -466,50 +463,54 @@ void MainWindow::updateEditorColorSchemes()
item = pColorManager->getItem(schemeName, SYNS_AttrFunction);
QColor baseColor = palette().color(QPalette::Base);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skFunction,item);
mStatementColors->insert(StatementKind::skConstructor,item);
mStatementColors->insert(StatementKind::skDestructor,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrClass);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skClass,item);
mStatementColors->insert(StatementKind::skTypedef,item);
mStatementColors->insert(StatementKind::skAlias,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrIdentifier);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skEnumType,item);
mStatementColors->insert(StatementKind::skEnumClassType,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrVariable);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skVariable,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrLocalVariable);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skLocalVariable,item);
mStatementColors->insert(StatementKind::skParameter,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrGlobalVariable);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skGlobalVariable,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrPreprocessor);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skPreprocessor,item);
mStatementColors->insert(StatementKind::skEnum,item);
mHeaderCompletionPopup->setSuggestionColor(item->foreground());
if (haveGoodContrast(item->foreground(), baseColor)) {
mHeaderCompletionPopup->setSuggestionColor(item->foreground());
} else {
mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text));
}
} else {
mHeaderCompletionPopup->setSuggestionColor(palette().color(QPalette::Text));
}
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skKeyword,item);
mStatementColors->insert(StatementKind::skUserCodeSnippet,item);
}
item = pColorManager->getItem(schemeName, SYNS_AttrString);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
if (item) {
mStatementColors->insert(StatementKind::skNamespace,item);
mStatementColors->insert(StatementKind::skNamespaceAlias,item);
}
@ -1119,7 +1120,7 @@ bool MainWindow::compile(bool rebuild)
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
clearIssues();
if (editor->modified()) {
if (editor->modified() || editor->isNew()) {
if (!editor->save(false,false))
return false;
}
@ -1210,7 +1211,7 @@ void MainWindow::runExecutable(RunType runType)
} else {
Editor * editor = mEditorList->getEditor();
if (editor != NULL ) {
if (editor->modified()) {
if (editor->modified() || editor->isNew()) {
if (!editor->save(false,false))
return;
}
@ -1342,13 +1343,12 @@ void MainWindow::debug()
Editor* e = mEditorList->getEditor();
if (e!=nullptr) {
// Did we saved?
if (e->modified()) {
if (e->modified() || e->isNew()) {
// if file is modified,save it first
if (!e->save(false,false))
return;
}
// Did we compiled?
filePath = getCompiledExecutableName(e->filename());
debugFile.setFile(filePath);
@ -1386,7 +1386,9 @@ void MainWindow::debug()
}
break;
default:
break;
//don't compile
updateEditorActions();
return;
}
updateEditorActions();
@ -2673,6 +2675,14 @@ void MainWindow::onNewProblemConnection()
clientConnection->disconnectFromHost();
}
void MainWindow::onEditorClosed()
{
if (mQuitting)
return;
updateEditorActions();
updateAppTitle();
}
void MainWindow::onShowInsertCodeSnippetMenu()
{
mMenuInsertCodeSnippet->clear();
@ -5200,3 +5210,22 @@ void MainWindow::on_btnRunAllProblemCases_clicked()
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 onProblemNameChanged(int index);
void onNewProblemConnection();
void onEditorClosed();
void onShowInsertCodeSnippetMenu();
@ -467,6 +468,10 @@ private slots:
void on_btnRunAllProblemCases_clicked();
void on_actionC_Reference_triggered();
void on_btnRemoveProblemCase_clicked();
private:
Ui::MainWindow *ui;
EditorList *mEditorList;

View File

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

View File

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

View File

@ -852,3 +852,9 @@ QByteArray getHTTPBody(const QByteArray& content) {
}
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);
int compareFileModifiedTime(const QString& filename1, const QString& filename2);
QByteArray getHTTPBody(const QByteArray& content);
bool haveGoodContrast(const QColor& c1, const QColor &c2);
//void changeTheme(const QString& themeName);

View File

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

View File

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

View File

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

View File

@ -236,6 +236,8 @@ bool HeaderCompletionPopup::event(QEvent *event)
case QEvent::FontChange:
mListView->setFont(font());
break;
default:
break;
}
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();
}

View File

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