修正大量demo

This commit is contained in:
feiyangqingyun
2021-03-08 09:04:48 +08:00
parent 2f5f9bd427
commit 23a32e6d32
32 changed files with 428 additions and 209 deletions

View File

@@ -86,14 +86,14 @@ ColorWidget::ColorWidget(QWidget *parent) : QWidget(parent)
txtPoint = new QLineEdit(this); txtPoint = new QLineEdit(this);
gridLayout->addWidget(txtPoint, 2, 2, 1, 1); gridLayout->addWidget(txtPoint, 2, 2, 1, 1);
label->setText("当前颜色显示"); label->setText("当前颜色");
labWeb->setText("web值:"); labWeb->setText("web值:");
labRgb->setText("rgb值:"); labRgb->setText("rgb值:");
labPoint->setText("坐标值:"); labPoint->setText("坐标值:");
this->setLayout(gridLayout); this->setLayout(gridLayout);
this->setWindowTitle("屏幕拾色器"); this->setWindowTitle("屏幕拾色器");
this->setFixedSize(270, 108); this->setFixedSize(300, 108);
cp = QApplication::clipboard(); cp = QApplication::clipboard();
pressed = false; pressed = false;

View File

@@ -14,5 +14,10 @@ DESTDIR = $$PWD/../bin
CONFIG += warn_off CONFIG += warn_off
SOURCES += main.cpp SOURCES += main.cpp
SOURCES += frmcolorwidget.cpp
SOURCES += colorwidget.cpp SOURCES += colorwidget.cpp
HEADERS += colorwidget.h HEADERS += colorwidget.h
HEADERS += frmcolorwidget.h
FORMS += frmcolorwidget.ui

View File

@@ -0,0 +1,18 @@
#include "frmcolorwidget.h"
#include "ui_frmcolorwidget.h"
#include "colorwidget.h"
frmColorWidget::frmColorWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmColorWidget)
{
ui->setupUi(this);
}
frmColorWidget::~frmColorWidget()
{
delete ui;
}
void frmColorWidget::on_pushButton_clicked()
{
ColorWidget::Instance()->show();
}

View File

@@ -0,0 +1,25 @@
#ifndef FRMCOLORWIDGET_H
#define FRMCOLORWIDGET_H
#include <QWidget>
namespace Ui {
class frmColorWidget;
}
class frmColorWidget : public QWidget
{
Q_OBJECT
public:
explicit frmColorWidget(QWidget *parent = 0);
~frmColorWidget();
private slots:
void on_pushButton_clicked();
private:
Ui::frmColorWidget *ui;
};
#endif // FRMCOLORWIDGET_H

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>frmColorWidget</class>
<widget class="QWidget" name="frmColorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>92</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>弹出</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,9 +1,8 @@
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#include "colorwidget.h" #include "frmcolorwidget.h"
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#include <QIcon>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -24,7 +23,9 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForLocale(codec);
#endif #endif
ColorWidget::Instance()->show(); frmColorWidget w;
w.setWindowTitle("屏幕拾色器");
w.show();
return a.exec(); return a.exec();
} }

View File

@@ -22,7 +22,7 @@ void frmFramelessWidget::closeEvent(QCloseEvent *)
exit(0); exit(0);
} }
void frmFramelessWidget::on_btnOpen_clicked() void frmFramelessWidget::on_pushButton_clicked()
{ {
if (w == 0) { if (w == 0) {
w = new QWidget; w = new QWidget;

View File

@@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
class FramelessWidget; class FramelessWidget;
namespace Ui namespace Ui {
{
class frmFramelessWidget; class frmFramelessWidget;
} }
@@ -26,7 +25,7 @@ private:
FramelessWidget *frameless; FramelessWidget *frameless;
private slots: private slots:
void on_btnOpen_clicked(); void on_pushButton_clicked();
void stateChanged1(int arg1); void stateChanged1(int arg1);
void stateChanged2(int arg1); void stateChanged2(int arg1);
}; };

View File

@@ -13,17 +13,17 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<widget class="QPushButton" name="btnOpen"> <widget class="QPushButton" name="pushButton">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>181</width> <width>92</width>
<height>23</height> <height>28</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>弹窗无边框窗体</string> <string>弹</string>
</property> </property>
</widget> </widget>
</widget> </widget>

View File

@@ -0,0 +1,18 @@
#include "frmgifwidget.h"
#include "ui_frmgifwidget.h"
#include "gifwidget.h"
frmGifWidget::frmGifWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmGifWidget)
{
ui->setupUi(this);
}
frmGifWidget::~frmGifWidget()
{
delete ui;
}
void frmGifWidget::on_pushButton_clicked()
{
GifWidget::Instance()->show();
}

25
gifwidget/frmgifwidget.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef FRMGIFWIDGET_H
#define FRMGIFWIDGET_H
#include <QWidget>
namespace Ui {
class frmGifWidget;
}
class frmGifWidget : public QWidget
{
Q_OBJECT
public:
explicit frmGifWidget(QWidget *parent = 0);
~frmGifWidget();
private slots:
void on_pushButton_clicked();
private:
Ui::frmGifWidget *ui;
};
#endif // FRMGIFWIDGET_H

32
gifwidget/frmgifwidget.ui Normal file
View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>frmGifWidget</class>
<widget class="QWidget" name="frmGifWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>92</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>弹出</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -72,16 +72,13 @@ public:
}; };
// max, min, and abs functions // max, min, and abs functions
int GifIMax(int l, int r) int GifIMax(int l, int r) {
{
return l > r ? l : r; return l > r ? l : r;
} }
int GifIMin(int l, int r) int GifIMin(int l, int r) {
{
return l < r ? l : r; return l < r ? l : r;
} }
int GifIAbs(int i) int GifIAbs(int i) {
{
return i < 0 ? -i : i; return i < 0 ? -i : i;
} }
@@ -89,8 +86,7 @@ public:
// Takes as in/out parameters the current best color and its error - // Takes as in/out parameters the current best color and its error -
// only changes them if it finds a better color in its subtree. // only changes them if it finds a better color in its subtree.
// this is the major hotspot in the code at the moment. // this is the major hotspot in the code at the moment.
void GifGetClosestPaletteColor(GifPalette *pPal, int r, int g, int b, int &bestInd, int &bestDiff, int treeRoot = 1) void GifGetClosestPaletteColor(GifPalette *pPal, int r, int g, int b, int &bestInd, int &bestDiff, int treeRoot = 1) {
{
// base case, reached the bottom of the tree // base case, reached the bottom of the tree
if (treeRoot > (1 << pPal->bitDepth) - 1) { if (treeRoot > (1 << pPal->bitDepth) - 1) {
int ind = treeRoot - (1 << pPal->bitDepth); int ind = treeRoot - (1 << pPal->bitDepth);
@@ -131,8 +127,7 @@ public:
} }
} }
void GifSwapPixels(uint8_t *image, int pixA, int pixB) void GifSwapPixels(uint8_t *image, int pixA, int pixB) {
{
uint8_t rA = image[pixA * 4]; uint8_t rA = image[pixA * 4];
uint8_t gA = image[pixA * 4 + 1]; uint8_t gA = image[pixA * 4 + 1];
uint8_t bA = image[pixA * 4 + 2]; uint8_t bA = image[pixA * 4 + 2];
@@ -155,8 +150,7 @@ public:
} }
// just the partition operation from quicksort // just the partition operation from quicksort
int GifPartition(uint8_t *image, const int left, const int right, const int elt, int pivotIndex) int GifPartition(uint8_t *image, const int left, const int right, const int elt, int pivotIndex) {
{
const int pivotValue = image[(pivotIndex) * 4 + elt]; const int pivotValue = image[(pivotIndex) * 4 + elt];
GifSwapPixels(image, pivotIndex, right - 1); GifSwapPixels(image, pivotIndex, right - 1);
int storeIndex = left; int storeIndex = left;
@@ -179,8 +173,7 @@ public:
} }
// Perform an incomplete sort, finding all elements above and below the desired median // Perform an incomplete sort, finding all elements above and below the desired median
void GifPartitionByMedian(uint8_t *image, int left, int right, int com, int neededCenter) void GifPartitionByMedian(uint8_t *image, int left, int right, int com, int neededCenter) {
{
if (left < right - 1) { if (left < right - 1) {
int pivotIndex = left + (right - left) / 2; int pivotIndex = left + (right - left) / 2;
pivotIndex = GifPartition(image, left, right, com, pivotIndex); pivotIndex = GifPartition(image, left, right, com, pivotIndex);
@@ -199,8 +192,7 @@ public:
int numPixels, int firstElt, int numPixels, int firstElt,
int lastElt, int splitElt, int lastElt, int splitElt,
int splitDist, int treeNode, int splitDist, int treeNode,
bool buildForDither, GifPalette *pal) bool buildForDither, GifPalette *pal) {
{
if (lastElt <= firstElt || numPixels == 0) { if (lastElt <= firstElt || numPixels == 0) {
return; return;
} }
@@ -318,8 +310,7 @@ public:
// moves them to the fromt of th buffer. // moves them to the fromt of th buffer.
// This allows us to build a palette optimized for the colors of the // This allows us to build a palette optimized for the colors of the
// changed pixels only. // changed pixels only.
int GifPickChangedPixels( const uint8_t *lastFrame, uint8_t *frame, int numPixels ) int GifPickChangedPixels(const uint8_t *lastFrame, uint8_t *frame, int numPixels) {
{
int numChanged = 0; int numChanged = 0;
uint8_t *writeIter = frame; uint8_t *writeIter = frame;
for (int ii = 0; ii < numPixels; ++ii) { for (int ii = 0; ii < numPixels; ++ii) {
@@ -344,8 +335,7 @@ public:
const uint8_t *nextFrame, const uint8_t *nextFrame,
uint32_t width, uint32_t height, uint32_t width, uint32_t height,
int bitDepth, bool buildForDither, int bitDepth, bool buildForDither,
GifPalette *pPal ) GifPalette *pPal) {
{
pPal->bitDepth = bitDepth; pPal->bitDepth = bitDepth;
// SplitPalette is destructive (it sorts the pixels by color) so // SplitPalette is destructive (it sorts the pixels by color) so
@@ -377,8 +367,7 @@ public:
// Implements Floyd-Steinberg dithering, writes palette value to alpha // Implements Floyd-Steinberg dithering, writes palette value to alpha
void GifDitherImage(const uint8_t *lastFrame, const uint8_t *nextFrame, void GifDitherImage(const uint8_t *lastFrame, const uint8_t *nextFrame,
uint8_t *outFrame, uint32_t width, uint8_t *outFrame, uint32_t width,
uint32_t height, GifPalette *pPal ) uint32_t height, GifPalette *pPal) {
{
int numPixels = (int)(width * height); int numPixels = (int)(width * height);
// quantPixels initially holds color*256 for all pixels // quantPixels initially holds color*256 for all pixels
@@ -473,8 +462,7 @@ public:
// Picks palette colors for the image using simple thresholding, no dithering // Picks palette colors for the image using simple thresholding, no dithering
void GifThresholdImage(const uint8_t *lastFrame, const uint8_t *nextFrame, void GifThresholdImage(const uint8_t *lastFrame, const uint8_t *nextFrame,
uint8_t *outFrame, uint32_t width, uint32_t height, uint8_t *outFrame, uint32_t width, uint32_t height,
GifPalette *pPal ) GifPalette *pPal) {
{
uint32_t numPixels = width * height; uint32_t numPixels = width * height;
for (uint32_t ii = 0; ii < numPixels; ++ii) { for (uint32_t ii = 0; ii < numPixels; ++ii) {
// if a previous color is available, and it matches the current color, // if a previous color is available, and it matches the current color,
@@ -518,8 +506,7 @@ public:
}; };
// insert a single bit // insert a single bit
void GifWriteBit( GifBitStatus &stat, uint32_t bit ) void GifWriteBit(GifBitStatus &stat, uint32_t bit) {
{
bit = bit & 1; bit = bit & 1;
bit = bit << stat.bitIndex; bit = bit << stat.bitIndex;
stat.byte |= bit; stat.byte |= bit;
@@ -535,8 +522,7 @@ public:
} }
// write all bytes so far to the file // write all bytes so far to the file
void GifWriteChunk( FILE *f, GifBitStatus &stat ) void GifWriteChunk(FILE *f, GifBitStatus &stat) {
{
fputc((int)stat.chunkIndex, f); fputc((int)stat.chunkIndex, f);
fwrite(stat.chunk, 1, stat.chunkIndex, f); fwrite(stat.chunk, 1, stat.chunkIndex, f);
@@ -545,8 +531,7 @@ public:
stat.chunkIndex = 0; stat.chunkIndex = 0;
} }
void GifWriteCode( FILE *f, GifBitStatus &stat, uint32_t code, uint32_t length ) void GifWriteCode(FILE *f, GifBitStatus &stat, uint32_t code, uint32_t length) {
{
for (uint32_t ii = 0; ii < length; ++ii) { for (uint32_t ii = 0; ii < length; ++ii) {
GifWriteBit(stat, code); GifWriteBit(stat, code);
code = code >> 1; code = code >> 1;
@@ -563,8 +548,7 @@ public:
}; };
// write a 256-color (8-bit) image palette to the file // write a 256-color (8-bit) image palette to the file
void GifWritePalette( const GifPalette *pPal, FILE *f ) void GifWritePalette(const GifPalette *pPal, FILE *f) {
{
fputc(0, f); // first color: transparency fputc(0, f); // first color: transparency
fputc(0, f); fputc(0, f);
fputc(0, f); fputc(0, f);
@@ -582,8 +566,7 @@ public:
void GifWriteLzwImage(FILE *f, uint8_t *image, uint32_t left, void GifWriteLzwImage(FILE *f, uint8_t *image, uint32_t left,
uint32_t top, uint32_t width, uint32_t top, uint32_t width,
uint32_t height, uint32_t delay, uint32_t height, uint32_t delay,
GifPalette *pPal) GifPalette *pPal) {
{
// graphics control extension // graphics control extension
fputc(0x21, f); fputc(0x21, f);
fputc(0xf9, f); fputc(0xf9, f);
@@ -694,8 +677,7 @@ public:
bool GifBegin(GifWriter *writer, const char *filename, bool GifBegin(GifWriter *writer, const char *filename,
uint32_t width, uint32_t height, uint32_t width, uint32_t height,
uint32_t delay, int32_t bitDepth = 8, uint32_t delay, int32_t bitDepth = 8,
bool dither = false ) bool dither = false) {
{
(void)bitDepth; (void)bitDepth;
(void)dither; // Mute "Unused argument" warnings (void)dither; // Mute "Unused argument" warnings
#if defined(_MSC_VER) && (_MSC_VER >= 1400) #if defined(_MSC_VER) && (_MSC_VER >= 1400)
@@ -757,8 +739,7 @@ public:
// this may be handy to save bits in animations that don't change much. // this may be handy to save bits in animations that don't change much.
bool GifWriteFrame(GifWriter *writer, const uint8_t *image, bool GifWriteFrame(GifWriter *writer, const uint8_t *image,
uint32_t width, uint32_t height, uint32_t width, uint32_t height,
uint32_t delay, int bitDepth = 8, bool dither = false ) uint32_t delay, int bitDepth = 8, bool dither = false) {
{
if (!writer->f) { if (!writer->f) {
return false; return false;
} }
@@ -783,8 +764,7 @@ public:
// Writes the EOF code, closes the file handle, and frees temp memory used by a GIF. // Writes the EOF code, closes the file handle, and frees temp memory used by a GIF.
// Many if not most viewers will still display a GIF properly if the EOF code is missing, // Many if not most viewers will still display a GIF properly if the EOF code is missing,
// but it's still a good idea to write it out. // but it's still a good idea to write it out.
bool GifEnd( GifWriter *writer ) bool GifEnd(GifWriter *writer) {
{
if (!writer->f) { if (!writer->f) {
return false; return false;
} }

View File

@@ -24,6 +24,7 @@ class GifWidget : public QDialog
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth) Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
Q_PROPERTY(QColor bgColor READ getBgColor WRITE setBgColor) Q_PROPERTY(QColor bgColor READ getBgColor WRITE setBgColor)

View File

@@ -14,7 +14,12 @@ DESTDIR = $$PWD/../bin
CONFIG += warn_off CONFIG += warn_off
SOURCES += main.cpp SOURCES += main.cpp
SOURCES += frmgifwidget.cpp
SOURCES += gifwidget.cpp SOURCES += gifwidget.cpp
HEADERS += gifwidget.h HEADERS += gifwidget.h
HEADERS += frmgifwidget.h
HEADERS += gif.h HEADERS += gif.h
FORMS += frmgifwidget.ui
RESOURCES += main.qrc RESOURCES += main.qrc

View File

@@ -1,6 +1,6 @@
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#include "gifwidget.h" #include "frmgifwidget.h"
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#include <QIcon> #include <QIcon>
@@ -25,7 +25,9 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForLocale(codec);
#endif #endif
GifWidget::Instance()->show(); frmGifWidget w;
w.setWindowTitle("GIF录屏");
w.show();
return a.exec(); return a.exec();
} }

View File

@@ -4,12 +4,13 @@
#include "ui_frmmaskwidget.h" #include "ui_frmmaskwidget.h"
#include "maskwidget.h" #include "maskwidget.h"
#include "qdialog.h" #include "qdialog.h"
#include "qtimer.h"
#include "qdebug.h"
frmMaskWidget::frmMaskWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmMaskWidget) frmMaskWidget::frmMaskWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmMaskWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
MaskWidget::Instance()->setMainWidget(this); QTimer::singleShot(1000, this, SLOT(initForm()));
MaskWidget::Instance()->setDialogNames(QStringList() << "frmTest");
} }
frmMaskWidget::~frmMaskWidget() frmMaskWidget::~frmMaskWidget()
@@ -18,6 +19,12 @@ frmMaskWidget::~frmMaskWidget()
exit(0); exit(0);
} }
void frmMaskWidget::initForm()
{
MaskWidget::Instance()->setMainWidget(this->topLevelWidget());
MaskWidget::Instance()->setDialogNames(QStringList() << "frmTest");
}
void frmMaskWidget::on_pushButton_clicked() void frmMaskWidget::on_pushButton_clicked()
{ {
QDialog d; QDialog d;

View File

@@ -15,11 +15,12 @@ public:
explicit frmMaskWidget(QWidget *parent = 0); explicit frmMaskWidget(QWidget *parent = 0);
~frmMaskWidget(); ~frmMaskWidget();
private slots:
void on_pushButton_clicked();
private: private:
Ui::frmMaskWidget *ui; Ui::frmMaskWidget *ui;
private slots:
void initForm();
void on_pushButton_clicked();
}; };
#endif // FRMMASKWIDGET_H #endif // FRMMASKWIDGET_H

View File

@@ -18,12 +18,12 @@
<rect> <rect>
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>131</width> <width>92</width>
<height>23</height> <height>28</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>弹出遮罩窗体</string> <string>弹出</string>
</property> </property>
</widget> </widget>
</widget> </widget>

View File

@@ -3,8 +3,7 @@
#include <QWidget> #include <QWidget>
namespace Ui namespace Ui {
{
class frmMoveWidget; class frmMoveWidget;
} }

View File

@@ -55,14 +55,6 @@ bool MoveWidget::eventFilter(QObject *watched, QEvent *event)
return QObject::eventFilter(watched, event); return QObject::eventFilter(watched, event);
} }
void MoveWidget::setWidget(QWidget *widget)
{
if (this->widget == 0) {
this->widget = widget;
this->widget->installEventFilter(this);
}
}
void MoveWidget::setLeftButton(bool leftButton) void MoveWidget::setLeftButton(bool leftButton)
{ {
this->leftButton = leftButton; this->leftButton = leftButton;
@@ -72,3 +64,11 @@ void MoveWidget::setInControl(bool inControl)
{ {
this->inControl = inControl; this->inControl = inControl;
} }
void MoveWidget::setWidget(QWidget *widget)
{
if (this->widget == 0) {
this->widget = widget;
this->widget->installEventFilter(this);
}
}

View File

@@ -3,21 +3,15 @@
/** /**
* 通用控件移动类 作者:feiyangqingyun(QQ:517216493) 2019-9-28 * 通用控件移动类 作者:feiyangqingyun(QQ:517216493) 2019-9-28
* 1:可以指定需要移动的widget * 1. 可以指定需要移动的widget
* 2:可设置是否限定鼠标左键拖动 * 2. 可设置是否限定鼠标左键拖动
* 3:支持任意widget控件 * 3. 支持任意widget控件
*/ */
#include <QWidget> #include <QWidget>
#ifdef quc #ifdef quc
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) class Q_DECL_EXPORT MoveWidget : public QObject
#include <QtDesigner/QDesignerExportWidget>
#else
#include <QtUiPlugin/QDesignerExportWidget>
#endif
class QDESIGNER_WIDGET_EXPORT MoveWidget : public QObject
#else #else
class MoveWidget : public QObject class MoveWidget : public QObject
#endif #endif

View File

@@ -1,4 +1,5 @@
#include "frmpngtool.h" #pragma execution_character_set("utf-8")
#include "frmpngtool.h"
#include "ui_frmpngtool.h" #include "ui_frmpngtool.h"
#include "qfile.h" #include "qfile.h"
#include "qfiledialog.h" #include "qfiledialog.h"
@@ -40,7 +41,7 @@ void frmPngTool::on_btnOk_clicked()
//将单个文件加入队列 //将单个文件加入队列
QString currentFile = ui->txtFile->text().trimmed(); QString currentFile = ui->txtFile->text().trimmed();
if (currentFile.isEmpty()) { if (!currentFile.isEmpty()) {
files.append(currentFile); files.append(currentFile);
} }
@@ -51,7 +52,6 @@ void frmPngTool::on_btnOk_clicked()
QStringList filter; QStringList filter;
filter << "*.png"; filter << "*.png";
QStringList list = imagePath.entryList(filter); QStringList list = imagePath.entryList(filter);
foreach (QString str, list) { foreach (QString str, list) {
files.append(currentDir + "/" + str); files.append(currentDir + "/" + str);
} }
@@ -60,9 +60,10 @@ void frmPngTool::on_btnOk_clicked()
ui->progress->setRange(0, files.count()); ui->progress->setRange(0, files.count());
ui->progress->setValue(0); ui->progress->setValue(0);
ui->txtMain->clear();
int count = 0; int count = 0;
foreach (QString file, files) { foreach (QString file, files) {
qDebug() << "current file:" << file; ui->txtMain->append(file);
QImage image(file); QImage image(file);
image.save(file, "png"); image.save(file, "png");
count++; count++;
@@ -70,5 +71,5 @@ void frmPngTool::on_btnOk_clicked()
qApp->processEvents(); qApp->processEvents();
} }
qDebug() << "finsh"; ui->txtMain->append(QString("处理完成, 共 %1 个文件").arg(files.count()));
} }

View File

@@ -6,14 +6,24 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>437</width> <width>800</width>
<height>105</height> <height>600</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLineEdit" name="txtFile"/>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="btnOk">
<property name="text">
<string>执行转换</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLineEdit" name="txtDir"/> <widget class="QLineEdit" name="txtDir"/>
</item> </item>
@@ -24,9 +34,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QLineEdit" name="txtFile"/>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QPushButton" name="btnFile"> <widget class="QPushButton" name="btnFile">
<property name="text"> <property name="text">
@@ -37,29 +44,15 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QProgressBar" name="progress"> <widget class="QProgressBar" name="progress">
<property name="value"> <property name="value">
<number>24</number> <number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="3" column="0" colspan="2">
<widget class="QPushButton" name="btnOk"> <widget class="QTextEdit" name="txtMain"/>
<property name="text">
<string>执行转换</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@@ -0,0 +1,18 @@
#include "frmscreenwidget.h"
#include "ui_frmscreenwidget.h"
#include "screenwidget.h"
frmScreenWidget::frmScreenWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmScreenWidget)
{
ui->setupUi(this);
}
frmScreenWidget::~frmScreenWidget()
{
delete ui;
}
void frmScreenWidget::on_pushButton_clicked()
{
ScreenWidget::Instance()->showFullScreen();
}

View File

@@ -0,0 +1,25 @@
#ifndef FRMSCREENWIDGET_H
#define FRMSCREENWIDGET_H
#include <QWidget>
namespace Ui {
class frmScreenWidget;
}
class frmScreenWidget : public QWidget
{
Q_OBJECT
public:
explicit frmScreenWidget(QWidget *parent = 0);
~frmScreenWidget();
private slots:
void on_pushButton_clicked();
private:
Ui::frmScreenWidget *ui;
};
#endif // FRMSCREENWIDGET_H

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>frmScreenWidget</class>
<widget class="QWidget" name="frmScreenWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>92</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>弹出</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,9 +1,8 @@
#pragma execution_character_set("utf-8") #pragma execution_character_set("utf-8")
#include "screenwidget.h" #include "frmscreenwidget.h"
#include <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#include <QIcon>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -24,7 +23,9 @@ int main(int argc, char *argv[])
QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForLocale(codec);
#endif #endif
ScreenWidget::Instance()->showFullScreen(); frmScreenWidget w;
w.setWindowTitle("屏幕截图");
w.show();
return a.exec(); return a.exec();
} }

View File

@@ -14,5 +14,10 @@ DESTDIR = $$PWD/../bin
CONFIG += warn_off CONFIG += warn_off
SOURCES += main.cpp SOURCES += main.cpp
SOURCES += frmscreenwidget.cpp
SOURCES += screenwidget.cpp SOURCES += screenwidget.cpp
HEADERS += screenwidget.h HEADERS += screenwidget.h
HEADERS += frmscreenwidget.h
FORMS += frmscreenwidget.ui