diff --git a/colorwidget/colorwidget.cpp b/colorwidget/colorwidget.cpp index 557f80e..3409f21 100644 --- a/colorwidget/colorwidget.cpp +++ b/colorwidget/colorwidget.cpp @@ -86,14 +86,14 @@ ColorWidget::ColorWidget(QWidget *parent) : QWidget(parent) txtPoint = new QLineEdit(this); gridLayout->addWidget(txtPoint, 2, 2, 1, 1); - label->setText("当前颜色显示"); + label->setText("当前颜色"); labWeb->setText("web值:"); labRgb->setText("rgb值:"); labPoint->setText("坐标值:"); this->setLayout(gridLayout); this->setWindowTitle("屏幕拾色器"); - this->setFixedSize(270, 108); + this->setFixedSize(300, 108); cp = QApplication::clipboard(); pressed = false; diff --git a/colorwidget/colorwidget.h b/colorwidget/colorwidget.h index bc6f927..70bdb30 100644 --- a/colorwidget/colorwidget.h +++ b/colorwidget/colorwidget.h @@ -19,7 +19,7 @@ class ColorWidget : public QWidget public: static ColorWidget *Instance(); explicit ColorWidget(QWidget *parent = 0); - ~ColorWidget(); + ~ColorWidget(); protected: void mousePressEvent(QMouseEvent *); diff --git a/colorwidget/colorwidget.pro b/colorwidget/colorwidget.pro index da7c56b..460cf1b 100644 --- a/colorwidget/colorwidget.pro +++ b/colorwidget/colorwidget.pro @@ -14,5 +14,10 @@ DESTDIR = $$PWD/../bin CONFIG += warn_off SOURCES += main.cpp +SOURCES += frmcolorwidget.cpp SOURCES += colorwidget.cpp + HEADERS += colorwidget.h +HEADERS += frmcolorwidget.h + +FORMS += frmcolorwidget.ui diff --git a/colorwidget/frmcolorwidget.cpp b/colorwidget/frmcolorwidget.cpp new file mode 100644 index 0000000..20d56fa --- /dev/null +++ b/colorwidget/frmcolorwidget.cpp @@ -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(); +} diff --git a/colorwidget/frmcolorwidget.h b/colorwidget/frmcolorwidget.h new file mode 100644 index 0000000..3412bab --- /dev/null +++ b/colorwidget/frmcolorwidget.h @@ -0,0 +1,25 @@ +#ifndef FRMCOLORWIDGET_H +#define FRMCOLORWIDGET_H + +#include + +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 diff --git a/colorwidget/frmcolorwidget.ui b/colorwidget/frmcolorwidget.ui new file mode 100644 index 0000000..bb01454 --- /dev/null +++ b/colorwidget/frmcolorwidget.ui @@ -0,0 +1,32 @@ + + + frmColorWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 10 + 10 + 92 + 28 + + + + 弹出 + + + + + + diff --git a/colorwidget/main.cpp b/colorwidget/main.cpp index 025223f..e872570 100644 --- a/colorwidget/main.cpp +++ b/colorwidget/main.cpp @@ -1,9 +1,8 @@ #pragma execution_character_set("utf-8") -#include "colorwidget.h" +#include "frmcolorwidget.h" #include #include -#include int main(int argc, char *argv[]) { @@ -24,7 +23,9 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); #endif - ColorWidget::Instance()->show(); + frmColorWidget w; + w.setWindowTitle("屏幕拾色器"); + w.show(); return a.exec(); } diff --git a/framelesswidget/framelesswidget.cpp b/framelesswidget/framelesswidget.cpp index e7b613d..8c852f8 100644 --- a/framelesswidget/framelesswidget.cpp +++ b/framelesswidget/framelesswidget.cpp @@ -205,6 +205,6 @@ void FramelessWidget::setWidget(QWidget *widget) //绑定事件过滤器 this->widget->installEventFilter(this); //设置悬停为真,必须设置这个,不然当父窗体里边还有子窗体全部遮挡了识别不到MouseMove,需要识别HoverMove - this->widget->setAttribute(Qt::WA_Hover, true); + this->widget->setAttribute(Qt::WA_Hover, true); } } diff --git a/framelesswidget/frmframelesswidget.cpp b/framelesswidget/frmframelesswidget.cpp index 944e9cb..8fd5dd3 100644 --- a/framelesswidget/frmframelesswidget.cpp +++ b/framelesswidget/frmframelesswidget.cpp @@ -22,7 +22,7 @@ void frmFramelessWidget::closeEvent(QCloseEvent *) exit(0); } -void frmFramelessWidget::on_btnOpen_clicked() +void frmFramelessWidget::on_pushButton_clicked() { if (w == 0) { w = new QWidget; diff --git a/framelesswidget/frmframelesswidget.h b/framelesswidget/frmframelesswidget.h index 487ccb7..52d23c5 100644 --- a/framelesswidget/frmframelesswidget.h +++ b/framelesswidget/frmframelesswidget.h @@ -4,9 +4,8 @@ #include class FramelessWidget; -namespace Ui -{ - class frmFramelessWidget; +namespace Ui { +class frmFramelessWidget; } class frmFramelessWidget : public QWidget @@ -26,7 +25,7 @@ private: FramelessWidget *frameless; private slots: - void on_btnOpen_clicked(); + void on_pushButton_clicked(); void stateChanged1(int arg1); void stateChanged2(int arg1); }; diff --git a/framelesswidget/frmframelesswidget.ui b/framelesswidget/frmframelesswidget.ui index 12b90c9..3b84e10 100644 --- a/framelesswidget/frmframelesswidget.ui +++ b/framelesswidget/frmframelesswidget.ui @@ -13,17 +13,17 @@ Form - + 10 10 - 181 - 23 + 92 + 28 - 弹窗无边框窗体 + 弹出 diff --git a/gifwidget/frmgifwidget.cpp b/gifwidget/frmgifwidget.cpp new file mode 100644 index 0000000..be8b074 --- /dev/null +++ b/gifwidget/frmgifwidget.cpp @@ -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(); +} diff --git a/gifwidget/frmgifwidget.h b/gifwidget/frmgifwidget.h new file mode 100644 index 0000000..05991d7 --- /dev/null +++ b/gifwidget/frmgifwidget.h @@ -0,0 +1,25 @@ +#ifndef FRMGIFWIDGET_H +#define FRMGIFWIDGET_H + +#include + +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 diff --git a/gifwidget/frmgifwidget.ui b/gifwidget/frmgifwidget.ui new file mode 100644 index 0000000..3b93ae6 --- /dev/null +++ b/gifwidget/frmgifwidget.ui @@ -0,0 +1,32 @@ + + + frmGifWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 10 + 10 + 92 + 28 + + + + 弹出 + + + + + + diff --git a/gifwidget/gif.h b/gifwidget/gif.h index fe797d9..02c24ed 100644 --- a/gifwidget/gif.h +++ b/gifwidget/gif.h @@ -72,16 +72,13 @@ public: }; // max, min, and abs functions - int GifIMax(int l, int r) - { + int GifIMax(int l, int r) { return l > r ? l : r; } - int GifIMin(int l, int r) - { + int GifIMin(int l, int r) { return l < r ? l : r; } - int GifIAbs(int i) - { + int GifIAbs(int i) { return i < 0 ? -i : i; } @@ -89,12 +86,11 @@ public: // Takes as in/out parameters the current best color and its error - // only changes them if it finds a better color in its subtree. // 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 - if(treeRoot > (1 << pPal->bitDepth) - 1) { + if (treeRoot > (1 << pPal->bitDepth) - 1) { int ind = treeRoot - (1 << pPal->bitDepth); - if(ind == kGifTransIndex) { + if (ind == kGifTransIndex) { return; } // check whether this color is better than the current winner @@ -102,7 +98,7 @@ public: int g_err = g - ((int32_t)pPal->g[ind]); int b_err = b - ((int32_t)pPal->b[ind]); int diff = GifIAbs(r_err) + GifIAbs(g_err) + GifIAbs(b_err); - if(diff < bestDiff) { + if (diff < bestDiff) { bestInd = ind; bestDiff = diff; } @@ -116,23 +112,22 @@ public: int splitComp = comps[pPal->treeSplitElt[treeRoot]]; int splitPos = pPal->treeSplit[treeRoot]; - if(splitPos > splitComp) { + if (splitPos > splitComp) { // check the left subtree GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot * 2); - if( bestDiff > splitPos - splitComp ) { + if (bestDiff > splitPos - splitComp) { // cannot prove there's not a better value in the right subtree, check that too GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot * 2 + 1); } } else { GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot * 2 + 1); - if( bestDiff > splitComp - splitPos ) { + if (bestDiff > splitComp - splitPos) { GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot * 2); } } } - 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 gA = image[pixA * 4 + 1]; uint8_t bA = image[pixA * 4 + 2]; @@ -155,19 +150,18 @@ public: } // 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]; GifSwapPixels(image, pivotIndex, right - 1); int storeIndex = left; bool split = 0; - for(int ii = left; ii < right - 1; ++ii) { + for (int ii = left; ii < right - 1; ++ii) { int arrayVal = image[ii * 4 + elt]; - if( arrayVal < pivotValue ) { + if (arrayVal < pivotValue) { GifSwapPixels(image, ii, storeIndex); ++storeIndex; - } else if( arrayVal == pivotValue ) { - if(split) { + } else if (arrayVal == pivotValue) { + if (split) { GifSwapPixels(image, ii, storeIndex); ++storeIndex; } @@ -179,16 +173,15 @@ public: } // 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) { int pivotIndex = left + (right - left) / 2; pivotIndex = GifPartition(image, left, right, com, pivotIndex); // Only "sort" the section of the array that contains the median - if(pivotIndex > neededCenter) { + if (pivotIndex > neededCenter) { GifPartitionByMedian(image, left, pivotIndex, com, neededCenter); } - if(pivotIndex < neededCenter) { + if (pivotIndex < neededCenter) { GifPartitionByMedian(image, pivotIndex + 1, right, com, neededCenter); } } @@ -199,8 +192,7 @@ public: int numPixels, int firstElt, int lastElt, int splitElt, int splitDist, int treeNode, - bool buildForDither, GifPalette *pal) - { + bool buildForDither, GifPalette *pal) { if (lastElt <= firstElt || numPixels == 0) { return; } @@ -210,10 +202,10 @@ public: // Dithering needs at least one color as dark as anything // in the image and at least one brightest color - // otherwise it builds up error and produces strange artifacts - if( firstElt == 1 ) { + if (firstElt == 1) { // special case: the darkest color in the image uint32_t r = 255, g = 255, b = 255; - for(int ii = 0; ii < numPixels; ++ii) { + for (int ii = 0; ii < numPixels; ++ii) { r = (uint32_t)GifIMin((int32_t)r, image[ii * 4 + 0]); g = (uint32_t)GifIMin((int32_t)g, image[ii * 4 + 1]); b = (uint32_t)GifIMin((int32_t)b, image[ii * 4 + 2]); @@ -224,10 +216,10 @@ public: return; } - if ( firstElt == (1 << pal->bitDepth) - 1 ) { + if (firstElt == (1 << pal->bitDepth) - 1) { // special case: the lightest color in the image uint32_t r = 0, g = 0, b = 0; - for(int ii = 0; ii < numPixels; ++ii) { + for (int ii = 0; ii < numPixels; ++ii) { r = (uint32_t)GifIMax((int32_t)r, image[ii * 4 + 0]); g = (uint32_t)GifIMax((int32_t)g, image[ii * 4 + 1]); b = (uint32_t)GifIMax((int32_t)b, image[ii * 4 + 2]); @@ -263,29 +255,29 @@ public: int minR = 255, maxR = 0; int minG = 255, maxG = 0; int minB = 255, maxB = 0; - for(int ii = 0; ii < numPixels; ++ii) { + for (int ii = 0; ii < numPixels; ++ii) { int r = image[ii * 4 + 0]; int g = image[ii * 4 + 1]; int b = image[ii * 4 + 2]; - if(r > maxR) { + if (r > maxR) { maxR = r; } - if(r < minR) { + if (r < minR) { minR = r; } - if(g > maxG) { + if (g > maxG) { maxG = g; } - if(g < minG) { + if (g < minG) { minG = g; } - if(b > maxB) { + if (b > maxB) { maxB = b; } - if(b < minB) { + if (b < minB) { minB = b; } } @@ -318,14 +310,13 @@ public: // moves them to the fromt of th buffer. // This allows us to build a palette optimized for the colors of the // 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; uint8_t *writeIter = frame; for (int ii = 0; ii < numPixels; ++ii) { - if(lastFrame[0] != frame[0] || - lastFrame[1] != frame[1] || - lastFrame[2] != frame[2]) { + if (lastFrame[0] != frame[0] || + lastFrame[1] != frame[1] || + lastFrame[2] != frame[2]) { writeIter[0] = frame[0]; writeIter[1] = frame[1]; writeIter[2] = frame[2]; @@ -340,12 +331,11 @@ public: // Creates a palette by placing all the image pixels in a k-d tree and then averaging the blocks at the bottom. // This is known as the "modified median split" technique - void GifMakePalette( const uint8_t *lastFrame, - const uint8_t *nextFrame, - uint32_t width, uint32_t height, - int bitDepth, bool buildForDither, - GifPalette *pPal ) - { + void GifMakePalette(const uint8_t *lastFrame, + const uint8_t *nextFrame, + uint32_t width, uint32_t height, + int bitDepth, bool buildForDither, + GifPalette *pPal) { pPal->bitDepth = bitDepth; // SplitPalette is destructive (it sorts the pixels by color) so @@ -355,7 +345,7 @@ public: memcpy(destroyableImage, nextFrame, imageSize); int numPixels = (int)(width * height); - if(lastFrame) { + if (lastFrame) { numPixels = GifPickChangedPixels(lastFrame, destroyableImage, numPixels); } @@ -375,24 +365,23 @@ public: } // Implements Floyd-Steinberg dithering, writes palette value to alpha - void GifDitherImage( const uint8_t *lastFrame, const uint8_t *nextFrame, - uint8_t *outFrame, uint32_t width, - uint32_t height, GifPalette *pPal ) - { + void GifDitherImage(const uint8_t *lastFrame, const uint8_t *nextFrame, + uint8_t *outFrame, uint32_t width, + uint32_t height, GifPalette *pPal) { int numPixels = (int)(width * height); // quantPixels initially holds color*256 for all pixels // The extra 8 bits of precision allow for sub-single-color error values // to be propagated int32_t *quantPixels = (int32_t *)GIF_TEMP_MALLOC(sizeof(int32_t) * (size_t)numPixels * 4); - for( int ii = 0; ii < numPixels * 4; ++ii ) { + for (int ii = 0; ii < numPixels * 4; ++ii) { uint8_t pix = nextFrame[ii]; int32_t pix16 = int32_t(pix) * 256; quantPixels[ii] = pix16; } - for( uint32_t yy = 0; yy < height; ++yy ) { - for( uint32_t xx = 0; xx < width; ++xx ) { + for (uint32_t yy = 0; yy < height; ++yy) { + for (uint32_t xx = 0; xx < width; ++xx) { int32_t *nextPix = quantPixels + 4 * (yy * width + xx); const uint8_t *lastPix = lastFrame ? lastFrame + 4 * (yy * width + xx) : NULL; // Compute the colors we want (rounding to nearest) @@ -401,10 +390,10 @@ public: int32_t bb = (nextPix[2] + 127) / 256; // if it happens that we want the color from last frame, then just write out // a transparent pixel - if( lastFrame && - lastPix[0] == rr && - lastPix[1] == gg && - lastPix[2] == bb ) { + if (lastFrame && + lastPix[0] == rr && + lastPix[1] == gg && + lastPix[2] == bb) { nextPix[0] = rr; nextPix[1] = gg; nextPix[2] = bb; @@ -433,37 +422,37 @@ public: int quantloc_5 = (int)(yy * width + width + xx); int quantloc_1 = (int)(yy * width + width + xx + 1); - if(quantloc_7 < numPixels) { + if (quantloc_7 < numPixels) { int32_t *pix7 = quantPixels + 4 * quantloc_7; - pix7[0] += GifIMax( -pix7[0], r_err * 7 / 16 ); - pix7[1] += GifIMax( -pix7[1], g_err * 7 / 16 ); - pix7[2] += GifIMax( -pix7[2], b_err * 7 / 16 ); + pix7[0] += GifIMax(-pix7[0], r_err * 7 / 16); + pix7[1] += GifIMax(-pix7[1], g_err * 7 / 16); + pix7[2] += GifIMax(-pix7[2], b_err * 7 / 16); } - if(quantloc_3 < numPixels) { + if (quantloc_3 < numPixels) { int32_t *pix3 = quantPixels + 4 * quantloc_3; - pix3[0] += GifIMax( -pix3[0], r_err * 3 / 16 ); - pix3[1] += GifIMax( -pix3[1], g_err * 3 / 16 ); - pix3[2] += GifIMax( -pix3[2], b_err * 3 / 16 ); + pix3[0] += GifIMax(-pix3[0], r_err * 3 / 16); + pix3[1] += GifIMax(-pix3[1], g_err * 3 / 16); + pix3[2] += GifIMax(-pix3[2], b_err * 3 / 16); } - if(quantloc_5 < numPixels) { + if (quantloc_5 < numPixels) { int32_t *pix5 = quantPixels + 4 * quantloc_5; - pix5[0] += GifIMax( -pix5[0], r_err * 5 / 16 ); - pix5[1] += GifIMax( -pix5[1], g_err * 5 / 16 ); - pix5[2] += GifIMax( -pix5[2], b_err * 5 / 16 ); + pix5[0] += GifIMax(-pix5[0], r_err * 5 / 16); + pix5[1] += GifIMax(-pix5[1], g_err * 5 / 16); + pix5[2] += GifIMax(-pix5[2], b_err * 5 / 16); } - if(quantloc_1 < numPixels) { + if (quantloc_1 < numPixels) { int32_t *pix1 = quantPixels + 4 * quantloc_1; - pix1[0] += GifIMax( -pix1[0], r_err / 16 ); - pix1[1] += GifIMax( -pix1[1], g_err / 16 ); - pix1[2] += GifIMax( -pix1[2], b_err / 16 ); + pix1[0] += GifIMax(-pix1[0], r_err / 16); + pix1[1] += GifIMax(-pix1[1], g_err / 16); + pix1[2] += GifIMax(-pix1[2], b_err / 16); } } } // Copy the palettized result to the output buffer - for( int ii = 0; ii < numPixels * 4; ++ii ) { + for (int ii = 0; ii < numPixels * 4; ++ii) { outFrame[ii] = (uint8_t)quantPixels[ii]; } @@ -471,18 +460,17 @@ public: } // Picks palette colors for the image using simple thresholding, no dithering - void GifThresholdImage( const uint8_t *lastFrame, const uint8_t *nextFrame, - uint8_t *outFrame, uint32_t width, uint32_t height, - GifPalette *pPal ) - { + void GifThresholdImage(const uint8_t *lastFrame, const uint8_t *nextFrame, + uint8_t *outFrame, uint32_t width, uint32_t height, + GifPalette *pPal) { 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, // set the pixel to transparent - if(lastFrame && - lastFrame[0] == nextFrame[0] && - lastFrame[1] == nextFrame[1] && - lastFrame[2] == nextFrame[2]) { + if (lastFrame && + lastFrame[0] == nextFrame[0] && + lastFrame[1] == nextFrame[1] && + lastFrame[2] == nextFrame[2]) { outFrame[0] = lastFrame[0]; outFrame[1] = lastFrame[1]; outFrame[2] = lastFrame[2]; @@ -499,7 +487,7 @@ public: outFrame[2] = pPal->b[bestInd]; outFrame[3] = (uint8_t)bestInd; } - if(lastFrame) { + if (lastFrame) { lastFrame += 4; } outFrame += 4; @@ -518,14 +506,13 @@ public: }; // insert a single bit - void GifWriteBit( GifBitStatus &stat, uint32_t bit ) - { + void GifWriteBit(GifBitStatus &stat, uint32_t bit) { bit = bit & 1; bit = bit << stat.bitIndex; stat.byte |= bit; ++stat.bitIndex; - if( stat.bitIndex > 7 ) { + if (stat.bitIndex > 7) { // move the newly-finished byte to the chunk buffer stat.chunk[stat.chunkIndex++] = stat.byte; // and start a new byte @@ -535,8 +522,7 @@ public: } // 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); fwrite(stat.chunk, 1, stat.chunkIndex, f); @@ -545,12 +531,11 @@ public: stat.chunkIndex = 0; } - void GifWriteCode( FILE *f, GifBitStatus &stat, uint32_t code, uint32_t length ) - { - for( uint32_t ii = 0; ii < length; ++ii ) { + void GifWriteCode(FILE *f, GifBitStatus &stat, uint32_t code, uint32_t length) { + for (uint32_t ii = 0; ii < length; ++ii) { GifWriteBit(stat, code); code = code >> 1; - if( stat.chunkIndex == 255 ) { + if (stat.chunkIndex == 255) { GifWriteChunk(f, stat); } } @@ -563,12 +548,11 @@ public: }; // 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); fputc(0, f); - for(int ii = 1; ii < (1 << pPal->bitDepth); ++ii) { + for (int ii = 1; ii < (1 << pPal->bitDepth); ++ii) { uint32_t r = pPal->r[ii]; uint32_t g = pPal->g[ii]; uint32_t b = pPal->b[ii]; @@ -582,8 +566,7 @@ public: void GifWriteLzwImage(FILE *f, uint8_t *image, uint32_t left, uint32_t top, uint32_t width, uint32_t height, uint32_t delay, - GifPalette *pPal) - { + GifPalette *pPal) { // graphics control extension fputc(0x21, f); fputc(0xf9, f); @@ -631,16 +614,16 @@ public: GifWriteCode(f, stat, clearCode, codeSize); // start with a fresh LZW dictionary - for(uint32_t yy = 0; yy < height; ++yy) { - for(uint32_t xx = 0; xx < width; ++xx) { + for (uint32_t yy = 0; yy < height; ++yy) { + for (uint32_t xx = 0; xx < width; ++xx) { uint8_t nextValue = image[(yy * width + xx) * 4 + 3]; // "loser mode" - no compression, every single code is followed immediately by a clear //WriteCode( f, stat, nextValue, codeSize ); //WriteCode( f, stat, 256, codeSize ); - if( curCode < 0 ) { + if (curCode < 0) { // first value in a new run curCode = nextValue; - } else if( codetree[curCode].m_next[nextValue] ) { + } else if (codetree[curCode].m_next[nextValue]) { // current run already in the dictionary curCode = codetree[curCode].m_next[nextValue]; } else { @@ -648,12 +631,12 @@ public: GifWriteCode(f, stat, (uint32_t)curCode, codeSize); // insert the new run into the dictionary codetree[curCode].m_next[nextValue] = (uint16_t)++maxCode; - if( maxCode >= (1ul << codeSize) ) { + if (maxCode >= (1ul << codeSize)) { // dictionary entry count has broken a size barrier, // we need more bits for codes codeSize++; } - if( maxCode == 4095 ) { + if (maxCode == 4095) { // the dictionary is full, clear it out and begin anew GifWriteCode(f, stat, clearCode, codeSize); // clear tree @@ -670,10 +653,10 @@ public: GifWriteCode(f, stat, clearCode, codeSize); GifWriteCode(f, stat, clearCode + 1, (uint32_t)minCodeSize + 1); // write out the last partial chunk - while( stat.bitIndex ) { + while (stat.bitIndex) { GifWriteBit(stat, 0); } - if( stat.chunkIndex ) { + if (stat.chunkIndex) { GifWriteChunk(f, stat); } @@ -691,11 +674,10 @@ public: // Creates a gif file. // The input GIFWriter is assumed to be uninitialized. // The delay value is the time between frames in hundredths of a second - note that not all viewers pay much attention to this value. - bool GifBegin( GifWriter *writer, const char *filename, - uint32_t width, uint32_t height, - uint32_t delay, int32_t bitDepth = 8, - bool dither = false ) - { + bool GifBegin(GifWriter *writer, const char *filename, + uint32_t width, uint32_t height, + uint32_t delay, int32_t bitDepth = 8, + bool dither = false) { (void)bitDepth; (void)dither; // Mute "Unused argument" warnings #if defined(_MSC_VER) && (_MSC_VER >= 1400) @@ -704,7 +686,7 @@ public: #else writer->f = fopen(filename, "wb"); #endif - if(!writer->f) { + if (!writer->f) { return false; } @@ -734,7 +716,7 @@ public: fputc(0, writer->f); fputc(0, writer->f); - if( delay != 0 ) { + if (delay != 0) { // animation header fputc(0x21, writer->f); // extension fputc(0xff, writer->f); // application specific @@ -755,11 +737,10 @@ public: // The GIFWriter should have been created by GIFBegin. // AFAIK, it is legal to use different bit depths for different frames of an image - // this may be handy to save bits in animations that don't change much. - bool GifWriteFrame( GifWriter *writer, const uint8_t *image, - uint32_t width, uint32_t height, - uint32_t delay, int bitDepth = 8, bool dither = false ) - { - if(!writer->f) { + bool GifWriteFrame(GifWriter *writer, const uint8_t *image, + uint32_t width, uint32_t height, + uint32_t delay, int bitDepth = 8, bool dither = false) { + if (!writer->f) { return false; } @@ -769,7 +750,7 @@ public: GifPalette pal; GifMakePalette((dither ? NULL : oldImage), image, width, height, bitDepth, dither, &pal); - if(dither) { + if (dither) { GifDitherImage(oldImage, image, writer->oldImage, width, height, &pal); } else { GifThresholdImage(oldImage, image, writer->oldImage, width, height, &pal); @@ -783,9 +764,8 @@ public: // 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, // but it's still a good idea to write it out. - bool GifEnd( GifWriter *writer ) - { - if(!writer->f) { + bool GifEnd(GifWriter *writer) { + if (!writer->f) { return false; } diff --git a/gifwidget/gifwidget.h b/gifwidget/gifwidget.h index b99ce25..b82088e 100644 --- a/gifwidget/gifwidget.h +++ b/gifwidget/gifwidget.h @@ -24,6 +24,7 @@ class GifWidget : public QDialog { Q_OBJECT + Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth) Q_PROPERTY(QColor bgColor READ getBgColor WRITE setBgColor) diff --git a/gifwidget/gifwidget.pro b/gifwidget/gifwidget.pro index 39eb595..b9ed176 100644 --- a/gifwidget/gifwidget.pro +++ b/gifwidget/gifwidget.pro @@ -14,7 +14,12 @@ DESTDIR = $$PWD/../bin CONFIG += warn_off SOURCES += main.cpp +SOURCES += frmgifwidget.cpp SOURCES += gifwidget.cpp + HEADERS += gifwidget.h +HEADERS += frmgifwidget.h HEADERS += gif.h + +FORMS += frmgifwidget.ui RESOURCES += main.qrc diff --git a/gifwidget/main.cpp b/gifwidget/main.cpp index 327bf26..8c6b27f 100644 --- a/gifwidget/main.cpp +++ b/gifwidget/main.cpp @@ -1,6 +1,6 @@ #pragma execution_character_set("utf-8") -#include "gifwidget.h" +#include "frmgifwidget.h" #include #include #include @@ -25,7 +25,9 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); #endif - GifWidget::Instance()->show(); + frmGifWidget w; + w.setWindowTitle("GIF录屏"); + w.show(); return a.exec(); } diff --git a/maskwidget/frmmaskwidget.cpp b/maskwidget/frmmaskwidget.cpp index 60b97a2..1893132 100644 --- a/maskwidget/frmmaskwidget.cpp +++ b/maskwidget/frmmaskwidget.cpp @@ -4,12 +4,13 @@ #include "ui_frmmaskwidget.h" #include "maskwidget.h" #include "qdialog.h" +#include "qtimer.h" +#include "qdebug.h" frmMaskWidget::frmMaskWidget(QWidget *parent) : QWidget(parent), ui(new Ui::frmMaskWidget) { ui->setupUi(this); - MaskWidget::Instance()->setMainWidget(this); - MaskWidget::Instance()->setDialogNames(QStringList() << "frmTest"); + QTimer::singleShot(1000, this, SLOT(initForm())); } frmMaskWidget::~frmMaskWidget() @@ -18,6 +19,12 @@ frmMaskWidget::~frmMaskWidget() exit(0); } +void frmMaskWidget::initForm() +{ + MaskWidget::Instance()->setMainWidget(this->topLevelWidget()); + MaskWidget::Instance()->setDialogNames(QStringList() << "frmTest"); +} + void frmMaskWidget::on_pushButton_clicked() { QDialog d; diff --git a/maskwidget/frmmaskwidget.h b/maskwidget/frmmaskwidget.h index 5e17fa5..1b0010f 100644 --- a/maskwidget/frmmaskwidget.h +++ b/maskwidget/frmmaskwidget.h @@ -15,11 +15,12 @@ public: explicit frmMaskWidget(QWidget *parent = 0); ~frmMaskWidget(); -private slots: - void on_pushButton_clicked(); - private: Ui::frmMaskWidget *ui; + +private slots: + void initForm(); + void on_pushButton_clicked(); }; #endif // FRMMASKWIDGET_H diff --git a/maskwidget/frmmaskwidget.ui b/maskwidget/frmmaskwidget.ui index 727df8e..a7a1923 100644 --- a/maskwidget/frmmaskwidget.ui +++ b/maskwidget/frmmaskwidget.ui @@ -18,12 +18,12 @@ 10 10 - 131 - 23 + 92 + 28 - 弹出遮罩窗体 + 弹出 diff --git a/movewidget/frmmovewidget.h b/movewidget/frmmovewidget.h index 67bce7d..463cf32 100644 --- a/movewidget/frmmovewidget.h +++ b/movewidget/frmmovewidget.h @@ -3,9 +3,8 @@ #include -namespace Ui -{ - class frmMoveWidget; +namespace Ui { +class frmMoveWidget; } class frmMoveWidget : public QWidget diff --git a/movewidget/movewidget.cpp b/movewidget/movewidget.cpp index 9caf390..6e9315d 100644 --- a/movewidget/movewidget.cpp +++ b/movewidget/movewidget.cpp @@ -55,14 +55,6 @@ bool MoveWidget::eventFilter(QObject *watched, QEvent *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) { this->leftButton = leftButton; @@ -72,3 +64,11 @@ void MoveWidget::setInControl(bool inControl) { this->inControl = inControl; } + +void MoveWidget::setWidget(QWidget *widget) +{ + if (this->widget == 0) { + this->widget = widget; + this->widget->installEventFilter(this); + } +} \ No newline at end of file diff --git a/movewidget/movewidget.h b/movewidget/movewidget.h index a25150b..43f7b6c 100644 --- a/movewidget/movewidget.h +++ b/movewidget/movewidget.h @@ -3,21 +3,15 @@ /** * 通用控件移动类 作者:feiyangqingyun(QQ:517216493) 2019-9-28 - * 1:可以指定需要移动的widget - * 2:可设置是否限定鼠标左键拖动 - * 3:支持任意widget控件 + * 1. 可以指定需要移动的widget + * 2. 可设置是否限定鼠标左键拖动 + * 3. 支持任意widget控件 */ #include #ifdef quc -#if (QT_VERSION < QT_VERSION_CHECK(5,7,0)) -#include -#else -#include -#endif - -class QDESIGNER_WIDGET_EXPORT MoveWidget : public QObject +class Q_DECL_EXPORT MoveWidget : public QObject #else class MoveWidget : public QObject #endif diff --git a/pngtool/frmpngtool.cpp b/pngtool/frmpngtool.cpp index 5005dd0..07d49d8 100644 --- a/pngtool/frmpngtool.cpp +++ b/pngtool/frmpngtool.cpp @@ -1,4 +1,5 @@ -#include "frmpngtool.h" +#pragma execution_character_set("utf-8") +#include "frmpngtool.h" #include "ui_frmpngtool.h" #include "qfile.h" #include "qfiledialog.h" @@ -40,7 +41,7 @@ void frmPngTool::on_btnOk_clicked() //将单个文件加入队列 QString currentFile = ui->txtFile->text().trimmed(); - if (currentFile.isEmpty()) { + if (!currentFile.isEmpty()) { files.append(currentFile); } @@ -51,7 +52,6 @@ void frmPngTool::on_btnOk_clicked() QStringList filter; filter << "*.png"; QStringList list = imagePath.entryList(filter); - foreach (QString str, list) { files.append(currentDir + "/" + str); } @@ -60,9 +60,10 @@ void frmPngTool::on_btnOk_clicked() ui->progress->setRange(0, files.count()); ui->progress->setValue(0); + ui->txtMain->clear(); int count = 0; foreach (QString file, files) { - qDebug() << "current file:" << file; + ui->txtMain->append(file); QImage image(file); image.save(file, "png"); count++; @@ -70,5 +71,5 @@ void frmPngTool::on_btnOk_clicked() qApp->processEvents(); } - qDebug() << "finsh"; + ui->txtMain->append(QString("处理完成, 共 %1 个文件").arg(files.count())); } diff --git a/pngtool/frmpngtool.ui b/pngtool/frmpngtool.ui index ca04371..33344f1 100644 --- a/pngtool/frmpngtool.ui +++ b/pngtool/frmpngtool.ui @@ -6,14 +6,24 @@ 0 0 - 437 - 105 + 800 + 600 Form + + + + + + + 执行转换 + + + @@ -24,9 +34,6 @@ - - - @@ -37,29 +44,15 @@ - 24 + 0 + + + Qt::AlignCenter - - - - 执行转换 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - + + diff --git a/screenwidget/frmscreenwidget.cpp b/screenwidget/frmscreenwidget.cpp new file mode 100644 index 0000000..c94eee2 --- /dev/null +++ b/screenwidget/frmscreenwidget.cpp @@ -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(); +} diff --git a/screenwidget/frmscreenwidget.h b/screenwidget/frmscreenwidget.h new file mode 100644 index 0000000..439024d --- /dev/null +++ b/screenwidget/frmscreenwidget.h @@ -0,0 +1,25 @@ +#ifndef FRMSCREENWIDGET_H +#define FRMSCREENWIDGET_H + +#include + +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 diff --git a/screenwidget/frmscreenwidget.ui b/screenwidget/frmscreenwidget.ui new file mode 100644 index 0000000..ba08e86 --- /dev/null +++ b/screenwidget/frmscreenwidget.ui @@ -0,0 +1,32 @@ + + + frmScreenWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 10 + 10 + 92 + 28 + + + + 弹出 + + + + + + diff --git a/screenwidget/main.cpp b/screenwidget/main.cpp index b8325f8..a297357 100644 --- a/screenwidget/main.cpp +++ b/screenwidget/main.cpp @@ -1,9 +1,8 @@ #pragma execution_character_set("utf-8") -#include "screenwidget.h" +#include "frmscreenwidget.h" #include #include -#include int main(int argc, char *argv[]) { @@ -24,7 +23,9 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); #endif - ScreenWidget::Instance()->showFullScreen(); + frmScreenWidget w; + w.setWindowTitle("屏幕截图"); + w.show(); return a.exec(); } diff --git a/screenwidget/screenwidget.h b/screenwidget/screenwidget.h index 8dbc0fa..bdb7ac4 100644 --- a/screenwidget/screenwidget.h +++ b/screenwidget/screenwidget.h @@ -73,8 +73,8 @@ protected: void paintEvent(QPaintEvent *); void showEvent(QShowEvent *); -private slots: - void saveScreen(); +private slots: + void saveScreen(); void saveFullScreen(); void saveScreenOther(); void saveFullOther(); diff --git a/screenwidget/screenwidget.pro b/screenwidget/screenwidget.pro index 10ebe50..f2f07cd 100644 --- a/screenwidget/screenwidget.pro +++ b/screenwidget/screenwidget.pro @@ -14,5 +14,10 @@ DESTDIR = $$PWD/../bin CONFIG += warn_off SOURCES += main.cpp +SOURCES += frmscreenwidget.cpp SOURCES += screenwidget.cpp + HEADERS += screenwidget.h +HEADERS += frmscreenwidget.h + +FORMS += frmscreenwidget.ui