- enhancement: Just keeping two digits after the decimal point for file size in the file properties dialog.

This commit is contained in:
Roy Qu 2023-04-19 18:07:19 +08:00
parent aded956ca8
commit c066919e2e
8 changed files with 366 additions and 332 deletions

View File

@ -5,6 +5,8 @@ Red Panda C++ Version 2.21
- fix: Horizontal scroll by touchpad is not working.
- fix: Horizontal scroll by touchpad is inversed.
- enhancement: Auto skip ; and , when input.
- enhancement: Add 'characters' column in the file properties dialog.
- enhancement: Just keeping two digits after the decimal point for file size in the file properties dialog.
Red Panda C++ Version 2.20

View File

@ -757,11 +757,7 @@
</message>
<message>
<source>MB</source>
<translation type="unfinished">MB</translation>
</message>
<message>
<source>Syntax error for stack frame larger than</source>
<translation type="unfinished"></translation>
<translation type="obsolete">MB</translation>
</message>
</context>
<context>
@ -2215,6 +2211,10 @@
<source>OK</source>
<translation>OK</translation>
</message>
<message>
<source>Characters:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FormatterGeneralWidget</name>

File diff suppressed because it is too large Load Diff

View File

@ -652,14 +652,6 @@
<source>Locate windres</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>MB</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Syntax error for stack frame larger than</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>CppRefacter</name>
@ -2048,6 +2040,10 @@
<source>OK</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Characters:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>FormatterGeneralWidget</name>

View File

@ -523,7 +523,7 @@ QString getSizeString(int size)
if (size < 1024) {
return QString("%1 ").arg(size)+QObject::tr("bytes");
} else if (size < 1024 * 1024) {
return QString("%1 ").arg(size / 1024.0)+QObject::tr("KB");
return QString("%1 ").arg(size / 1024.0,0,'f',2)+QObject::tr("KB");
} else if (size < 1024 * 1024 * 1024) {
return QString("%1 ").arg(size / 1024.0 / 1024.0)+QObject::tr("MB");
} else {

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "filepropertiesdialog.h"
#include "systemconsts.h"
#include "ui_filepropertiesdialog.h"
#include "../mainwindow.h"
#include "../editorlist.h"
@ -42,22 +43,25 @@ void FilePropertiesDialog::calcFile(Editor *editor,
int &commentLines,
int &emptyLines,
int &codeLines,
int &includeLines)
int &includeLines,
int &charCounts)
{
totalLines = editor->document()->count();
codeLines = 0;
commentLines = 0;
emptyLines = 0;
includeLines = 0;
charCounts = 0;
int lineBreakerLen = QString(LINE_BREAKER).length();
// iterate through all lines of file
for (int i=0;i<editor->document()->count();i++) {
QString line = editor->document()->getLine(i);
int j=0;
while (j<line.length() && (line[j]=='\t' || line[j]==' '))
j++;
charCounts+=line.length()+lineBreakerLen;
// while (j<line.length() && (line[j]=='\t' || line[j]==' '))
// j++;
QString token;
QSynedit::PTokenAttribute attr;
if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{j+1,i+1},
if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{1,i+1},
token,attr)) {
// if it is preprocessor...
if (attr->name() == SYNS_AttrPreprocessor) {
@ -134,14 +138,15 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index)
ui->txtRelativeToProject->setText("_");
ui->txtLines->setText(QString("%1").arg(editor->document()->count()));
int totalLines, codeLines,emptyLines,commentLines,includeLines;
calcFile(editor,totalLines,commentLines,emptyLines,codeLines,includeLines);
int totalLines, codeLines,emptyLines,commentLines,includeLines, charCounts;
calcFile(editor,totalLines,commentLines,emptyLines,codeLines,includeLines,charCounts);
ui->txtLines->setText(QString("%1").arg(totalLines));
ui->txtEmptyLines->setText(QString("%1").arg(emptyLines));
ui->txtCodeLines->setText(QString("%1").arg(codeLines));
ui->txtCommentLines->setText(QString("%1").arg(commentLines));
ui->txtIncludes->setText(QString("%1").arg(includeLines));
ui->txtCharacters->setText(QString("%1").arg(charCounts));
}
}

View File

@ -49,7 +49,8 @@ private:
int &commentLines,
int &emptyLines,
int &codeLines,
int &includeLines);
int &includeLines,
int &charCounts);
private:
FilePropertiesModel mModel;
Editor * mActiveEditor;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>726</width>
<height>444</height>
<height>471</height>
</rect>
</property>
<property name="windowTitle">
@ -228,58 +228,6 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QFrame" name="frame_6">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>File size:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtFileSize">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QFrame" name="frame_8">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>File date:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtFileDate">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
@ -319,6 +267,84 @@
</layout>
</widget>
</item>
<item row="4" column="1">
<widget class="QFrame" name="frame_8">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>File date:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtFileDate">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QFrame" name="frame_6">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>File size:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtFileSize">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QFrame" name="frame_9">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Characters:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txtCharacters">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>