├── LICENSE ├── QtDrawingBoard ├── DrawingBoard │ ├── DrawingBoard.pro │ ├── DrawingBoard.pro.user │ ├── dataupdatethread.h │ ├── drawingboard.cpp │ ├── drawingboard.h │ ├── img.qrc │ ├── main.cpp │ ├── screen.png │ └── wuli.png └── drawingboard.gif ├── QtPagingToolBar ├── LICENSE ├── PagingToolBar │ ├── .gitignore │ ├── PagingToolBar.pro │ ├── main.cpp │ ├── pagingtoolbar.cpp │ └── pagingtoolbar.h ├── README.md └── pagingtoolbar_show.gif ├── QtSliptBotton ├── README.md ├── SliptBotton │ ├── SliptBotton.pro │ ├── main.cpp │ ├── slipwt.cpp │ └── slipwt.h └── slipt_btn.png ├── QtTimer ├── README.CN ├── Timer │ ├── Timer.pro │ ├── Timer.pro.user │ ├── countdown.ico │ ├── main.cpp │ ├── timer.qrc │ ├── widget.cpp │ ├── widget.h │ └── widget.ui └── mytimer.gif ├── QtVirtualKeyboard ├── LICENSE ├── README.md ├── makeChinesePY_db │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── makeChinesePY_db.pro │ └── readme.cn └── useKeyBoard_Demo │ ├── .gitigore │ ├── .qmake.stash │ ├── keyboard_show-how.gif │ ├── main.cpp │ ├── moc_predefs.h │ ├── moc_virtualkeyboard.cpp │ ├── qrc_VirtualKeyBoardResource.cpp │ ├── ui_virtualkeyboard.h │ ├── useKeyBoard_Demo.pro │ └── virtualkeyboard_hasQSQLITE │ ├── Resource │ ├── ChinesePY.db │ ├── ICON │ │ ├── 128x128没有使用 │ │ │ ├── Earth-RGB210.png │ │ │ ├── back-RGB210.png │ │ │ ├── keyboard-hide-RGB210.png │ │ │ ├── left-RGB210.png │ │ │ ├── right-RGB210.png │ │ │ ├── shift-RGB210.png │ │ │ └── triangle-outline-RGB210.png │ │ ├── Earth-RGB60.png │ │ ├── back-RGB60.png │ │ ├── backspace-RGB60.png │ │ ├── keyboard-hide-RGB60.png │ │ ├── left-RGB60.png │ │ ├── return-RGB60.png │ │ ├── right-RGB60.png │ │ ├── shift-RGB60.png │ │ └── triangle-outline-RGB60.png │ ├── VirtualKeyBoardResource.qrc │ ├── keyboard.qss │ ├── readme.txt │ └── resource.qrc │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── myqbtn.cpp │ ├── myqbtn.h │ ├── myqlb.cpp │ ├── myqlb.h │ ├── myqproxystyle.cpp │ ├── myqproxystyle.h │ ├── readme.txt │ ├── virtualKeyBoard.pro │ ├── virtualKeyBoard.pro.user │ ├── virtualkeyboard.cpp │ ├── virtualkeyboard.h │ ├── virtualkeyboard.pri │ └── virtualkeyboard.ui ├── README.md ├── other └── QtRotatingInArmForQt5 │ ├── qt5.5.1_enable_rotate_transprant │ └── qtbase │ │ └── src │ │ ├── platformsupport │ │ └── fbconvenience │ │ │ ├── qfbscreen.cpp │ │ │ └── qfbscreen.cpp.bak │ │ └── plugins │ │ └── platforms │ │ └── linuxfb │ │ ├── qlinuxfbscreen.cpp │ │ ├── qlinuxfbscreen.cpp.bak │ │ ├── qlinuxfbscreen.cpp_patch │ │ ├── qlinuxfbscreen.h │ │ ├── qlinuxfbscreen.h.bak │ │ └── qlinuxfbscreen.h_patch │ └── readme.cn ├── qtproject.pro └── qtproject.pro.user /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Haijie He 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/DrawingBoard.pro: -------------------------------------------------------------------------------- 1 | 2 | QT += core gui 3 | 4 | 5 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 6 | 7 | CONFIG += c++11 8 | 9 | # The following define makes your compiler emit warnings if you use 10 | # any Qt feature that has been marked deprecated (the exact warnings 11 | # depend on your compiler). Please consult the documentation of the 12 | # deprecated API in order to know how to port your code away from it. 13 | DEFINES += QT_DEPRECATED_WARNINGS 14 | 15 | # You can also make your code fail to compile if it uses deprecated APIs. 16 | # In order to do so, uncomment the following line. 17 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 18 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 19 | 20 | SOURCES += \ 21 | main.cpp \ 22 | drawingboard.cpp 23 | 24 | HEADERS += \ 25 | drawingboard.h 26 | 27 | FORMS += 28 | 29 | # Default rules for deployment. 30 | qnx: target.path = /tmp/$${TARGET}/bin 31 | else: unix:!android: target.path = /opt/$${TARGET}/bin 32 | !isEmpty(target.path): INSTALLS += target 33 | 34 | RESOURCES += \ 35 | img.qrc 36 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/dataupdatethread.h: -------------------------------------------------------------------------------- 1 | #ifndef DATAUPDATETHREAD_H 2 | #define DATAUPDATETHREAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class DataUpdateThread : public QObject 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit DataUpdateThread(QObject *parent = nullptr); 14 | 15 | 16 | 17 | signals: 18 | 19 | 20 | public slots: 21 | void onUpdateData(QPixmap *pix, QVector lines); 22 | 23 | }; 24 | 25 | #endif // DATAUPDATETHREAD_H 26 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/drawingboard.cpp: -------------------------------------------------------------------------------- 1 | #include "drawingboard.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace DrawingBoardNameSpace; 10 | //QLabel *lb; 11 | 12 | DrawingBoard::DrawingBoard(QWidget *parent) 13 | : QWidget(parent) 14 | { 15 | this->setWindowFlags(Qt::Sheet | Qt::BypassWindowManagerHint);// 禁用所有插件 16 | this->setAttribute(Qt::WA_OpaquePaintEvent); //每次直接绘制指定范围内的全部像素,对不支持双缓冲的设备进行了优化 17 | 18 | drawPen_ = new QPen(); 19 | drawBrush_ = new QBrush(); 20 | 21 | drawPen_->setWidth(2); 22 | drawPen_->setBrush(Qt::SolidPattern); 23 | drawPen_->setColor(Qt::green); 24 | 25 | drawBrush_->setStyle(Qt::NoBrush); //Qpainter 填充使用的 26 | 27 | pixCache_ = new QPixmap; 28 | pix_ = new QPixmap; 29 | pixSrc_ = new QPixmap; 30 | 31 | setPix(":/screen.png"); 32 | } 33 | 34 | 35 | DrawingBoard::~DrawingBoard() 36 | { 37 | 38 | } 39 | 40 | void DrawingBoard::setPix(const QString &path, const QByteArray &orPixData) 41 | { 42 | if (path.isEmpty() && orPixData.isEmpty()) return; 43 | 44 | if (path.isEmpty()) pixSrc_->loadFromData(orPixData); 45 | else pixSrc_->load(path); 46 | 47 | *pix_ = *pixSrc_; 48 | *pixCache_ = *pix_; 49 | pixCache_->fill(Qt::transparent); 50 | } 51 | 52 | void DrawingBoard::setEraseMode(bool isErase) 53 | { 54 | isErase_ = isErase; 55 | } 56 | 57 | void DrawingBoard::setPen(const QPen &pen) 58 | { 59 | *drawPen_ = pen; 60 | } 61 | 62 | void DrawingBoard::setPixOffsetPoint(const QPoint &point) 63 | { 64 | offsetPoint_ = point; 65 | } 66 | 67 | void DrawingBoard::paintEvent(QPaintEvent *e) 68 | { 69 | if (pixSrc_->isNull()) return; 70 | 71 | (void) e; 72 | 73 | QPainter painter(this); 74 | 75 | //draw in the cache drawBoard 76 | drawInPix(points_, pixCache_); 77 | 78 | // if (isDrawBack_ || this->rect() == e->rect()) { // 发现在 arm 设备没有添加这个会 透明化 79 | // isDrawBack_ = false; 80 | painter.drawPixmap(e->rect(), *pix_, e->rect()); 81 | // } 82 | 83 | 84 | // 如果不需要擦除操作,可以直接将 *pixCache_ = *pix_; 然后 直接在 pixCache 上面画图, 可以减少一次画背景图的操作 85 | 86 | 87 | QRect pixRect(e->rect()); 88 | 89 | pixRect.setTopLeft(offsetPoint_ + pixRect.topLeft()); 90 | pixRect.setBottomRight(offsetPoint_ + pixRect.bottomRight()); 91 | 92 | painter.drawPixmap(e->rect(), *pixCache_, pixRect); 93 | 94 | if (isRelease_) { 95 | points_.clear(); 96 | } 97 | 98 | } 99 | 100 | void DrawingBoard::mouseMoveEvent(QMouseEvent *e) 101 | { 102 | if (isPress_) { 103 | // isMove_ = true; 104 | points_.append(e->pos()); 105 | this->update(updateUpdateArea(e->pos())); 106 | } 107 | 108 | } 109 | 110 | void DrawingBoard::mousePressEvent(QMouseEvent *e) 111 | { 112 | isRelease_ = false; 113 | isPress_ = true; 114 | 115 | topLeftPoint_ = e->pos(); 116 | bottomRightPoint_ = e->pos(); 117 | 118 | points_.clear(); 119 | points_.append(e->pos()); 120 | } 121 | 122 | void DrawingBoard::mouseReleaseEvent(QMouseEvent *e) 123 | { 124 | isRelease_ = true; 125 | isPress_ = false; 126 | if (this->rect().contains(e->pos())) { 127 | this->update(updateUpdateArea(e->pos())); 128 | } 129 | 130 | } 131 | 132 | void DrawingBoard::drawInPix(const QVector points, QPixmap *pixBoard) 133 | { 134 | QPainter painter(pixBoard); 135 | painter.setPen(*drawPen_); 136 | painter.setBrush(*drawBrush_); 137 | 138 | if (isErase_) { 139 | painter.setCompositionMode(QPainter::CompositionMode_Clear); 140 | } 141 | 142 | if (1 == points.count()) painter.drawPoint(points.first()); 143 | 144 | auto offsetX = offsetPoint_.x(); 145 | auto offsetY = offsetPoint_.y(); 146 | 147 | for (int i = 1; i < points.count(); ++i) { 148 | auto p1 = points.at(i - 1); 149 | auto p2 = points.at(i); 150 | p1.setX(p1.x() + offsetX); 151 | p1.setY(p1.y() + offsetY); 152 | 153 | p2.setX(p2.x() + offsetX); 154 | p2.setY(p2.y() + offsetY); 155 | 156 | painter.drawLine(p1, p2); 157 | } 158 | 159 | } 160 | 161 | const QRect DrawingBoard::updateUpdateArea(const QPoint &curPoint) 162 | { 163 | int curX = curPoint.x(); 164 | int curY = curPoint.y(); 165 | 166 | QPoint p1 = topLeftPoint_; 167 | QPoint p2 = bottomRightPoint_; 168 | 169 | 170 | int minX = qMin(qMin(curX, p1.x()), p2.x()); 171 | int minY = qMin(qMin(curY, p1.y()), p2.y()); 172 | 173 | int maxX = qMax(qMax(curX, p1.x()), p2.x()); 174 | int maxY = qMax(qMax(curY, p1.y()), p2.y()); 175 | 176 | if (minX < 0) minX = 0; 177 | if (minY < 0) minY = 0; 178 | if (maxX > this->width()) maxX = this->width(); 179 | if (maxY > this->height()) maxY = this->height(); 180 | 181 | 182 | topLeftPoint_ = {minX, minY}; 183 | bottomRightPoint_ = {maxX, maxY}; 184 | 185 | return QRect(topLeftPoint_, bottomRightPoint_); 186 | 187 | } 188 | 189 | void DrawingBoard::onRestoreChanged() 190 | { 191 | pixCache_->fill(Qt::transparent); 192 | *pix_ = *pixSrc_; 193 | this->update(); 194 | } 195 | 196 | void DrawingBoard::onSaveChanged() 197 | { 198 | QPainter p(pix_); 199 | if (!p.isActive()) p.begin(pix_); 200 | p.drawPixmap(0, 0, *pixCache_); 201 | *pixSrc_ = *pix_; 202 | } 203 | 204 | void DrawingBoard::onSavePix(QString path) 205 | { 206 | pixSrc_->save(path); 207 | } 208 | 209 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/drawingboard.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAWINGBOARD_H 2 | #define DRAWINGBOARD_H 3 | #include 4 | #include 5 | 6 | 7 | /* 8 | 功能: 可以擦除,可保存,可恢复画板 9 | 说明: 该画板在 qt5.9.8 下测试通过,目前在 ARM Cortex A7 双核 @1.3GHz 画图尚且流畅 10 | 有些是没有用到,例如 11 | 12 | offsetPoint_ 13 | 14 | */ 15 | 16 | 17 | 18 | 19 | namespace DrawingBoardNameSpace { 20 | 21 | #define LOGD qDebug()<<__func__ 22 | 23 | class DrawingBoard : public QWidget 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | DrawingBoard(QWidget* parent = nullptr); 29 | ~DrawingBoard(); 30 | 31 | 32 | void setPix(const QString &path, const QByteArray &orPixData = {}); 33 | void setEraseMode(bool isErase); 34 | void setPen(const QPen &pen); 35 | 36 | //TODO 37 | void setPixOffsetPoint(const QPoint &point); 38 | 39 | protected: 40 | 41 | void paintEvent(QPaintEvent *e) override; 42 | void mouseMoveEvent(QMouseEvent *e) override; 43 | void mousePressEvent(QMouseEvent *e) override; 44 | void mouseReleaseEvent(QMouseEvent *e) override; 45 | // void resizeEvent(QResizeEvent *e) override; 46 | 47 | private: 48 | //background picture, confirm tmp changed, tmp changed. 49 | // 背景图片, 提交临时变更, 临时绘图区域 50 | QPixmap *pixSrc_{}, *pix_{}, *pixCache_{}; 51 | QPoint offsetPoint_{}; 52 | QPoint topLeftPoint_{}, bottomRightPoint_{};//mark udpate area, save the cpu 53 | 54 | bool isPress_ = false, isMove_ = false, isRelease_ = false; 55 | QVector points_; 56 | 57 | QPen *drawPen_; 58 | QBrush *drawBrush_; 59 | bool isErase_ = false; 60 | bool isDrawBack_ = true; 61 | 62 | 63 | // 当画板大小与可见区域不一致时候,需要进行位置重定位 64 | void drawInPix(const QVector points, QPixmap *pixBoard); //在 paintervent 调用,就不 begin 了 65 | 66 | private: 67 | const QRect updateUpdateArea(const QPoint &curPoint); 68 | 69 | public slots: 70 | 71 | void onRestoreChanged(); 72 | void onSaveChanged(); 73 | void onSavePix(QString path); 74 | 75 | }; 76 | } 77 | 78 | 79 | #endif // DRAWINGBOARD_H 80 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/img.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | screen.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/main.cpp: -------------------------------------------------------------------------------- 1 | #include "drawingboard.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | QApplication a(argc, argv); 11 | 12 | QStackedWidget stack; 13 | 14 | 15 | stack.resize(500,500); 16 | 17 | DrawingBoardNameSpace::DrawingBoard b; 18 | b.resize(400,400); 19 | QWidget c; 20 | c.resize(300,300); 21 | c.setStyleSheet("QWidget{background:red;}"); 22 | 23 | stack.addWidget(&b); 24 | stack.addWidget(&c); 25 | 26 | stack.show(); 27 | 28 | 29 | // int i = 0; 30 | 31 | // QTimer t; 32 | // QObject::connect(&t, &QTimer::timeout, [&](){ 33 | // b.onRestoreChanged(); 34 | // }); 35 | 36 | // t.start(2000); 37 | 38 | return a.exec(); 39 | } 40 | -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtDrawingBoard/DrawingBoard/screen.png -------------------------------------------------------------------------------- /QtDrawingBoard/DrawingBoard/wuli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtDrawingBoard/DrawingBoard/wuli.png -------------------------------------------------------------------------------- /QtDrawingBoard/drawingboard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtDrawingBoard/drawingboard.gif -------------------------------------------------------------------------------- /QtPagingToolBar/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Haijie He 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /QtPagingToolBar/PagingToolBar/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /QtPagingToolBar/PagingToolBar/PagingToolBar.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | pagingtoolbar.cpp 21 | 22 | HEADERS += \ 23 | pagingtoolbar.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /QtPagingToolBar/PagingToolBar/main.cpp: -------------------------------------------------------------------------------- 1 | #include "pagingtoolbar.h" 2 | 3 | 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | PagingToolBar w; 10 | w.Init(5, true, Qt::AlignCenter); 11 | w.SetMaxPage(15); 12 | w.SetCurPage(1); 13 | w.show(); 14 | 15 | 16 | 17 | 18 | 19 | return a.exec(); 20 | } 21 | -------------------------------------------------------------------------------- /QtPagingToolBar/PagingToolBar/pagingtoolbar.cpp: -------------------------------------------------------------------------------- 1 | #include "pagingtoolbar.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | PagingToolBar::PagingToolBar(QWidget *parent) 10 | : QWidget(parent) 11 | { 12 | this->resize(600, 50); 13 | this->setObjectName("PagingToolBarwt"); 14 | 15 | // QStringList qss{}; 16 | // qss.append(R"( 17 | // QWidget#PagingToolBarwt QPushButton{ 18 | // border:1px solid #999999; 19 | // border-radius: 4px; 20 | // outline:none; 21 | // background-color:white; 22 | // font: 16pt; 23 | // color:#999999; 24 | // } 25 | // )"); 26 | 27 | 28 | // qss.append("QWidget#PagingToolBarwt QPushButton[selected=true]{background-color:green;color:white;}");//btn_1, ..., btn_max 29 | 30 | // // btn_prev 31 | // qss.append(R"( 32 | // QWidget#PagingToolBarwt QPushButton#btn_prev{ 33 | // image-position:center left; 34 | // padding-right:8px; 35 | // text-align:center; 36 | // } 37 | // )"); 38 | // qss.append(R"( 39 | // QWidget#PagingToolBarwt QPushButton#btn_prev:pressed{ 40 | // background-color:green; 41 | // color:white; 42 | // } 43 | // )"); 44 | 45 | // //btn_next 46 | // qss.append(R"( 47 | // QWidget#PagingToolBarwt QPushButton#btn_next{ 48 | // image-position:center right; 49 | // padding-left:8px; 50 | // text-align:center; 51 | // } 52 | // )"); 53 | 54 | // qss.append(R"( 55 | // QWidget#PagingToolBarwt QPushButton#btn_next:pressed{ 56 | // background-color:green; 57 | // color:white; 58 | // } 59 | // )"); 60 | 61 | 62 | 63 | // qss.append("QWidget#btn_wt QPushButton#btn_prev{background-color:red;}");//btn_prev 64 | // qss.append("QWidget#btn_wt QPushButton#btn_prev:pressed{background-color:black;color:red;}");//btn_prev 65 | // qss.append("QWidget#btn_wt QPushButton:checked{background-color:green;}");//btn_1, ..., btn_max 66 | // qss.append("QWidget#btn_wt QPushButton#btn_1:checked{background-color:green;}"); //btn_1,btn_2 ... btn_num 67 | // qss.append("QWidget#btn_wt QPushButton#btn_next{background-color:blue;}");//btn_next 68 | // qss.append("QWidget#btn_wt QPushButton#btn_next:pressed{background-color:black;color:blue;}");//btn_next 69 | 70 | 71 | // this->setStyleSheet(qss.join("")); 72 | // this->style()->unpolish(this); 73 | // this->style()->polish(this); 74 | // this->update(); 75 | } 76 | 77 | void PagingToolBar::Init(const int index_count, const bool auto_hide_btn_prev_next, const Qt::AlignmentFlag align) 78 | { 79 | 80 | auto layout1 = this->findChild(); 81 | if (nullptr != layout1) { 82 | qDebug()<<__func__<<"Inited"; 83 | return; 84 | } 85 | max_btn_index_ = index_count; 86 | 87 | auto_hide_btn_prev_next_ = auto_hide_btn_prev_next; 88 | btn_index_aligin_ = align; 89 | 90 | layout1 = new QHBoxLayout; 91 | auto layout2 = new QHBoxLayout; 92 | btn_wt_ = new QWidget(this); 93 | 94 | layout1->setMargin(0); 95 | layout1->setSpacing(0); 96 | layout1->addWidget(btn_wt_); 97 | 98 | this->setLayout(layout1); 99 | 100 | layout2->setMargin(0); 101 | layout2->setSpacing(10); 102 | 103 | btn_wt_->setObjectName("btn_wt"); // 1 2 3 4 5 6 ... 104 | btn_wt_->setLayout(layout2); 105 | 106 | int btn_total = max_btn_index_ + 2; 107 | 108 | for (int i = 0; i < btn_total; ++i) { 109 | QPushButton *btn = new QPushButton; 110 | QWidget *add_wt = btn; 111 | 112 | 113 | btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 114 | btn->setText(QString::number(i)); 115 | 116 | btn->setObjectName("btn_" + QString::number(i)); 117 | if (0 == i) { 118 | btn->setObjectName("btn_prev"); 119 | }else if (btn_total - 1 == i) { 120 | btn->setObjectName("btn_next"); 121 | } 122 | 123 | if (i > 0 && i < max_btn_index_ + 1) { 124 | btn->setProperty("btn_index", i); 125 | 126 | }else if (i == 0) { 127 | btn->setProperty("btn_index", i); //代表上一页, 外嵌套 一个 QWidget, hide 的时候不会影响布局 128 | 129 | auto layout_tmp = new QHBoxLayout; 130 | auto wt = new QWidget; 131 | 132 | layout_tmp->setMargin(0); 133 | layout_tmp->addWidget(btn); 134 | wt->setLayout(layout_tmp); 135 | add_wt = wt; 136 | 137 | 138 | }else if (i == max_btn_index_ + 1) { 139 | btn->setProperty("btn_index", i); //代表下一页 140 | 141 | auto layout_tmp = new QHBoxLayout; 142 | auto wt = new QWidget; 143 | 144 | 145 | layout_tmp->setMargin(0); 146 | layout_tmp->addWidget(btn); 147 | wt->setLayout(layout_tmp); 148 | add_wt = wt; 149 | } 150 | 151 | layout2->addWidget(add_wt); 152 | btns_.append(btn); 153 | connect(btn, &QPushButton::clicked, this, &PagingToolBar::SlotBtnClicked); 154 | 155 | if (0 == i || max_btn_index_ + 1 == i) { 156 | layout2->setStretch(i, btn_prev_next_strech_); 157 | }else { 158 | layout2->setStretch(i, 10); 159 | } 160 | 161 | } 162 | 163 | max_page_lb_ = new QLabel; 164 | max_page_lb_->setObjectName("max_page_lb"); 165 | max_page_lb_->setAlignment(Qt::AlignCenter); 166 | max_page_lb_->setText(QString("共 %1 页").arg(maxpage_)); 167 | layout2->addWidget(max_page_lb_); 168 | layout2->setStretch(layout2->count() - 1, 10); 169 | 170 | btns_.first()->setText("上一页"); //上一页 171 | btns_.last()->setText("下一页");//下一页 172 | 173 | 174 | layout1->insertSpacerItem(0, new QSpacerItem(QSizePolicy::Expanding, QSizePolicy::Expanding)); 175 | layout1->addItem(new QSpacerItem(QSizePolicy::Expanding, QSizePolicy::Expanding)); 176 | 177 | layout1->setStretch(0, 0); 178 | layout1->setStretch(1, btn_prev_next_strech_ + btn_prev_next_strech_ + 10 + max_btn_index_ * 10); //btn_prev, btn_next, max_page_lb 179 | layout1->setStretch(2, 0); 180 | 181 | SetCurPage(1); 182 | } 183 | 184 | void PagingToolBar::SetCurPage(const int cur_page) 185 | { 186 | if (cur_page < 1 || cur_page > maxpage_) { 187 | return; 188 | } 189 | 190 | cur_page_ = cur_page; 191 | const int max_btn_index = btns_.count() - 2; 192 | const int cur_btn_index = ((cur_page - btns_.at(1)->text().toInt() + 1) % max_btn_index == 0) ? 193 | (max_btn_index) : 194 | ((cur_page - btns_.at(1)->text().toInt() + 1) % max_btn_index); //当前被按下的按钮 195 | int after_btn_index = cur_btn_index;//接下来应该被选中的按钮 196 | int last_btn_index = 1; //当前处于被选中的按钮 197 | const int middle_btn_index = (max_btn_index % 2 > 0) ? (max_btn_index / 2 + 1) : (max_btn_index / 2); //偶数时候,选择左侧的为中点 198 | 199 | 200 | for (int i = 1; i < btns_.count() - 1; ++i) { 201 | if (btns_.at(i)->property("selected").toBool()) { 202 | last_btn_index = i; 203 | break; 204 | } 205 | } 206 | 207 | if (cur_btn_index > middle_btn_index) { // 靠近 “下一页” 208 | int cur_right_maxpage = btns_.at(max_btn_index)->text().toInt(); 209 | const int step = cur_btn_index - middle_btn_index; 210 | 211 | for (int i = step; i > 0 && cur_right_maxpage < maxpage_; --i) { //获取最右边可以取到的最大值 212 | ++cur_right_maxpage; 213 | --after_btn_index; 214 | } 215 | 216 | for (int i = max_btn_index, j = 0; i > 0 ; --i, ++j) { 217 | btns_.at(i)->setText(QString::number(cur_right_maxpage - j)); 218 | } 219 | 220 | }else if (cur_btn_index < middle_btn_index) { // 靠近 “上一页” 221 | int cur_left_minpage = btns_.at(1)->text().toInt(); 222 | const int step = middle_btn_index - cur_btn_index; 223 | 224 | for (int i = step; i > 0 && cur_left_minpage > 1; --i) { //获取最左边可以取到的最小值 225 | --cur_left_minpage; 226 | ++after_btn_index; 227 | } 228 | 229 | for (int i = 1, j = 0; i < btns_.count() - 1; ++i, ++j) { 230 | btns_.at(i)->setText(QString::number(cur_left_minpage + j)); 231 | } 232 | } 233 | 234 | 235 | //样式的选中与取消 236 | auto btn_last = btns_.at(last_btn_index); 237 | auto btn_after = btns_.at(after_btn_index); 238 | 239 | if (after_btn_index <= 1) { 240 | 241 | if (maxpage_ == 1 || auto_hide_btn_prev_next_) { 242 | btns_.at(0)->setVisible(false); 243 | btns_.at(1)->setVisible(false); 244 | } 245 | 246 | }else { 247 | btns_.at(0)->setVisible(true); 248 | btns_.at(1)->setVisible(true); 249 | } 250 | 251 | 252 | if ((max_btn_index == after_btn_index || maxpage_ == after_btn_index)) { 253 | 254 | if (maxpage_ == 1 || auto_hide_btn_prev_next_) { 255 | btns_.at(btns_.count() - 1)->setVisible(false); 256 | } 257 | 258 | 259 | }else if (maxpage_ > 1 || auto_hide_btn_prev_next_) { 260 | btns_.at(btns_.count() - 1)->setVisible(true); 261 | } 262 | 263 | 264 | if (btn_last != btn_after) { 265 | btn_last->setProperty("selected", false); 266 | btn_last->style()->unpolish(btn_last); 267 | btn_last->style()->polish(btn_last); 268 | btn_last->update(); 269 | } 270 | 271 | btn_after->setProperty("selected", true); 272 | btn_after->style()->unpolish(btn_after); 273 | btn_after->style()->polish(btn_after); 274 | btn_after->update(); 275 | 276 | 277 | //布局对齐方式 278 | if (maxpage_ < max_btn_index) { 279 | for (int i = maxpage_ + 1; i <= max_btn_index; ++i) { 280 | btns_.at(i)->setVisible(false); 281 | } 282 | 283 | int btn_index_visible = maxpage_; 284 | 285 | auto layout1 = this->findChild(); 286 | int free_spacing = ((max_btn_index - btn_index_visible) * 10); 287 | int middle = btn_index_visible * 10 + btn_prev_next_strech_ + btn_prev_next_strech_ + 10; //btn_prev, btn_next, max_page_lb 288 | 289 | QWidget *next_wt = static_cast(btns_.last()->parent()); 290 | QWidget *prev_wt = static_cast(btns_.first()->parent()); 291 | 292 | 293 | 294 | switch (btn_index_aligin_) { 295 | case (Qt::AlignLeft): { 296 | 297 | if (maxpage_ == 1) { 298 | prev_wt->setVisible(false); 299 | next_wt->setVisible(false); 300 | free_spacing = free_spacing + 10 + 10; 301 | middle = middle - 10 - 10; 302 | }else if (maxpage_ > 1){ 303 | if (auto_hide_btn_prev_next_) { 304 | if (after_btn_index > 1 & after_btn_index < maxpage_) { 305 | prev_wt->setVisible(true); 306 | } 307 | if (after_btn_index < maxpage_) { 308 | next_wt->setVisible(true); 309 | } 310 | }else { 311 | prev_wt->setVisible(true); 312 | next_wt->setVisible(true); 313 | } 314 | } 315 | 316 | layout1->setStretch(0, 0); 317 | layout1->setStretch(1, middle); 318 | layout1->setStretch(2, free_spacing); 319 | break; 320 | } 321 | case (Qt::AlignCenter): { 322 | 323 | layout1->setStretch(0, free_spacing / 2); 324 | layout1->setStretch(1, middle); 325 | layout1->setStretch(2, free_spacing / 2); 326 | 327 | break; 328 | } 329 | case (Qt::AlignRight): { 330 | 331 | if (maxpage_ == 1) { 332 | next_wt->setVisible(false); 333 | free_spacing = free_spacing + 10; 334 | middle = middle - 10; 335 | }else if (maxpage_ > 1){ 336 | if (auto_hide_btn_prev_next_) { 337 | if (after_btn_index < maxpage_) { 338 | next_wt->setVisible(true); 339 | } 340 | }else { 341 | next_wt->setVisible(true); 342 | } 343 | } 344 | 345 | layout1->setStretch(0, free_spacing); 346 | layout1->setStretch(1, middle); 347 | layout1->setStretch(2, 0); 348 | break; 349 | } 350 | default: { 351 | 352 | } 353 | 354 | } 355 | 356 | }else { 357 | for (int i = 1; i <= max_btn_index; ++i) { 358 | if (!btns_.at(i)->isVisible()) 359 | btns_.at(i)->setVisible(true); 360 | } 361 | } 362 | 363 | } 364 | 365 | 366 | 367 | void PagingToolBar::SetMaxPage(const int maxpage) 368 | { 369 | maxpage_ = maxpage; 370 | max_page_lb_->setText(QString("共 %1 页").arg(maxpage_)); 371 | 372 | if (0 == maxpage) { 373 | btn_wt_->setVisible(false); 374 | }else if (maxpage > 0) { 375 | btn_wt_->setVisible(true); 376 | if (maxpage > 1) { 377 | if (1 != cur_btn_index_) { 378 | btns_.first()->setVisible(true); 379 | } 380 | 381 | if (max_btn_index_ != cur_btn_index_) { 382 | btns_.last()->setVisible(true); 383 | } 384 | } 385 | 386 | for (int i = 1; i < btns_.count() - 2 && i < max_btn_index_; ++i) { 387 | btns_.at(i)->setVisible(true); 388 | } 389 | } 390 | 391 | } 392 | 393 | int PagingToolBar::GetMaxPage() const 394 | { 395 | return maxpage_; 396 | } 397 | 398 | int PagingToolBar::GetCurPage() const 399 | { 400 | return cur_page_; 401 | } 402 | 403 | 404 | PagingToolBar::~PagingToolBar() 405 | { 406 | 407 | } 408 | 409 | 410 | 411 | void PagingToolBar::SlotBtnClicked() 412 | { 413 | 414 | QPushButton *btn = static_cast(sender()); 415 | 416 | int btn_index = btn->property("btn_index").toInt(); 417 | int cur_page = cur_page_; 418 | 419 | 420 | if (btn_index > 0 && btn_index < btns_.count() - 1) { 421 | cur_page = btn->text().toInt(); 422 | }else if (btn_index == 0) {//上一页 423 | 424 | if (cur_page > 1) { 425 | --cur_page; 426 | }else { 427 | return; 428 | } 429 | 430 | }else if (btn_index == btns_.count() - 1) {//下一页 431 | 432 | if (cur_page < maxpage_) { 433 | ++cur_page; 434 | }else { 435 | return; 436 | } 437 | } 438 | 439 | SetCurPage(cur_page); 440 | emit SignalCurPageChanged(cur_page); 441 | } 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | -------------------------------------------------------------------------------- /QtPagingToolBar/PagingToolBar/pagingtoolbar.h: -------------------------------------------------------------------------------- 1 | #ifndef PAGINGTOOLBAR_H 2 | #define PAGINGTOOLBAR_H 3 | 4 | /* 5 | * @brief: 分页栏, 6 | * 允许左对齐、右对齐、居中对齐; 7 | * 允许自动隐藏翻页按钮 8 | * @author: LastSee 9 | * @date: 2020 10 | * 11 | */ 12 | 13 | #include 14 | class QPushButton; 15 | //class QHBoxLayout; 16 | class QLabel; 17 | 18 | 19 | 20 | class PagingToolBar : public QWidget 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | PagingToolBar(QWidget *parent = nullptr); 26 | void Init(const int index_count, const bool auto_hide_btn_prev_next, const Qt::AlignmentFlag align = Qt::AlignRight); 27 | void SetCurPage(const int cur_page); //样式: “上一页” 1 2 3 ... “下一页” 28 | void SetMaxPage(const int maxpage); 29 | int GetMaxPage() const; 30 | int GetCurPage() const; 31 | ~PagingToolBar(); 32 | 33 | private: 34 | QList btns_{}; 35 | QLabel *max_page_lb_{}; 36 | 37 | int max_btn_index_ = 0; 38 | int maxpage_ = 0; 39 | int cur_page_ = 1; 40 | int cur_btn_index_ = 0; 41 | QWidget *btn_wt_ = nullptr; 42 | bool auto_hide_btn_prev_next_ = false; 43 | int btn_prev_next_strech_ = 13; 44 | Qt::AlignmentFlag btn_index_aligin_ = Qt::AlignRight; // Qt::AlignLeft; AlignCenter Qt::AlignRight; 当按钮较少时候,整体右对齐 45 | 46 | 47 | signals: 48 | void SignalCurPageChanged(const int curpage); 49 | 50 | public slots: 51 | 52 | private slots: 53 | void SlotBtnClicked(); 54 | }; 55 | #endif // PAGINGTOOLBAR_H 56 | -------------------------------------------------------------------------------- /QtPagingToolBar/README.md: -------------------------------------------------------------------------------- 1 | 分页栏 2 | 切换页面序号,类似 百度、goolge 网页底部 ”上一页 1 2 3 4 5 6 7 8 9 10 下一页“ 3 | 4 | 这里使用自定义属性来完成样式更新,之所以不使用自带的 :checked 是由于在 CPU 较差 5 | 的情况下,切换页面的时候,渲染过程可见。 6 | 7 | 1、可以自定义需要显示的分页数量; 8 | 2、当最大页数小于最大分页数量时候,可选择左对齐、居中、右对齐; 9 | 3、在首页或者末页时候,可选是否自动隐藏翻页按钮; 10 | -------------------------------------------------------------------------------- /QtPagingToolBar/pagingtoolbar_show.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtPagingToolBar/pagingtoolbar_show.gif -------------------------------------------------------------------------------- /QtSliptBotton/README.md: -------------------------------------------------------------------------------- 1 | # QtProject 2 | 单选滑块按钮 3 | 1、背景色、按钮色自由更改 4 | 2、自适应大小更改 5 | 6 | -------------------------------------------------------------------------------- /QtSliptBotton/SliptBotton/SliptBotton.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | slipwt.cpp 21 | 22 | HEADERS += \ 23 | slipwt.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /QtSliptBotton/SliptBotton/main.cpp: -------------------------------------------------------------------------------- 1 | #include "slipwt.h" 2 | 3 | 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | Slipwt w; 10 | 11 | w.show(); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /QtSliptBotton/SliptBotton/slipwt.cpp: -------------------------------------------------------------------------------- 1 | #include "slipwt.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | Slipwt::Slipwt(QWidget *parent) : QWidget(parent) 10 | { 11 | 12 | slipbtn_ = new QPushButton(this); 13 | 14 | ani_ = new QPropertyAnimation(slipbtn_, "pos", this); 15 | ani_->setEasingCurve(QEasingCurve::Linear); 16 | ani_->setDuration(100); 17 | 18 | connect(slipbtn_, &QPushButton::clicked, this, &Slipwt::SlotBtnClicked); 19 | 20 | SetChecked(false); 21 | SetColors(); 22 | UpdateStyleSheet(); 23 | } 24 | 25 | 26 | void Slipwt::SetChecked(const bool ischecked) 27 | { 28 | ischecked_ = ischecked; 29 | if (ischecked_) { 30 | slipbtn_->move(this->width() - slipbtn_->width(), 0); 31 | }else { 32 | slipbtn_->move(0, 0); 33 | } 34 | } 35 | 36 | void Slipwt::SetColors(const QString &background_normal, const QString &background_checked, const QString &btn) 37 | { 38 | background_normal_color_ = background_normal; 39 | background_checked_color_ = background_checked; 40 | btn_color_ = btn; 41 | this->update(); 42 | } 43 | 44 | 45 | 46 | void Slipwt::resizeEvent(QResizeEvent *e) 47 | { 48 | this->resize(e->size()); 49 | slipbtn_->resize(this->height(), this->height()); 50 | 51 | UpdateStyleSheet(); 52 | return QWidget::resizeEvent(e); 53 | } 54 | 55 | void Slipwt::paintEvent(QPaintEvent *) 56 | { 57 | QPainter painter(this); 58 | painter.setRenderHint(QPainter::Antialiasing); 59 | painter.setPen(Qt::transparent); 60 | 61 | QString color{}; 62 | if (ischecked_) { 63 | color = background_checked_color_; 64 | }else { 65 | color = background_normal_color_; 66 | } 67 | 68 | painter.setBrush(QBrush(QColor(color))); 69 | painter.drawRoundedRect(this->rect(), this->height() / 2, this->height() / 2); 70 | 71 | } 72 | 73 | 74 | void Slipwt::UpdateStyleSheet() 75 | { 76 | QStringList qss{}; 77 | 78 | // qss.append(QString(R"(QWidget{border: 0px solid black; border-radius: %1px; background: %2;})").arg(this->height()).arg("#ff0000"));//invalid 79 | qss.append(QString(R"(QPushButton{border: none; outline: none; border-radius: %1px; background-color: %2;})").arg(this->height() / 2).arg(btn_color_)); 80 | SetChecked(ischecked_); 81 | 82 | this->setStyleSheet(qss.join("")); 83 | this->style()->unpolish(this); 84 | this->style()->polish(this); 85 | this->update(); 86 | } 87 | 88 | 89 | void Slipwt::SlotBtnClicked() 90 | { 91 | 92 | if (QPropertyAnimation::Running == ani_->state()) { 93 | return; 94 | } 95 | ischecked_ = !ischecked_; 96 | 97 | if (ischecked_) { 98 | ani_->setStartValue(slipbtn_->pos()); 99 | ani_->setEndValue(QPoint(this->width() - slipbtn_->width(), 0)); 100 | }else { 101 | ani_->setStartValue(slipbtn_->pos()); 102 | ani_->setEndValue(QPoint(0, 0)); 103 | } 104 | 105 | ani_->start(); 106 | this->update(); 107 | 108 | SignalCheckedChanged(ischecked_); 109 | } 110 | -------------------------------------------------------------------------------- /QtSliptBotton/SliptBotton/slipwt.h: -------------------------------------------------------------------------------- 1 | #ifndef SLIPWT_H 2 | #define SLIPWT_H 3 | 4 | #include 5 | class QPushButton; 6 | class QPropertyAnimation; 7 | //class QLabel; 8 | 9 | 10 | class Slipwt : public QWidget 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit Slipwt(QWidget *parent = nullptr); 15 | void SetChecked(const bool ischecked); 16 | void SetColors(const QString& background_normal = "#ababab", const QString& background_checked = "#00ff00", const QString& btn = "#ffffff"); 17 | 18 | protected: 19 | void resizeEvent(QResizeEvent * e) override; 20 | void paintEvent(QPaintEvent *) override; 21 | 22 | private: 23 | QPushButton *slipbtn_; 24 | QPropertyAnimation* ani_; 25 | 26 | QString background_normal_color_; 27 | QString background_checked_color_; 28 | QString btn_color_; 29 | 30 | bool ischecked_ = false; 31 | void UpdateStyleSheet(); 32 | 33 | signals: 34 | void SignalCheckedChanged(const bool ischecked); 35 | 36 | private slots: 37 | void SlotBtnClicked(); 38 | 39 | }; 40 | 41 | #endif // SLIPWT_H 42 | -------------------------------------------------------------------------------- /QtSliptBotton/slipt_btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtSliptBotton/slipt_btn.png -------------------------------------------------------------------------------- /QtTimer/README.CN: -------------------------------------------------------------------------------- 1 | 方便提醒自己. 找定时器挺麻烦的,所以自己弄了一个简易版本的. 2 | 时间到达, 强制弹窗 3 | 4 | 若是要放到环境变量, 建议使用脚本启动: 5 | (/usr/local/mytimer &) 6 | 让 mytimer 脱离当前终端控制, 可以看这里解释: https://www.linuxidc.com/Linux/2011-02/32062.htm 7 | -------------------------------------------------------------------------------- /QtTimer/Timer/Timer.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | 4 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 5 | 6 | CONFIG += c++17 7 | 8 | # The following define makes your compiler emit warnings if you use 9 | # any Qt feature that has been marked deprecated (the exact warnings 10 | # depend on your compiler). Please consult the documentation of the 11 | # deprecated API in order to know how to port your code away from it. 12 | #DEFINES += QT_DEPRECATED_WARNINGS 13 | 14 | # You can also make your code fail to compile if it uses deprecated APIs. 15 | # In order to do so, uncomment the following line. 16 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 17 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 18 | 19 | SOURCES += \ 20 | main.cpp \ 21 | widget.cpp 22 | 23 | HEADERS += \ 24 | widget.h 25 | 26 | FORMS += \ 27 | widget.ui 28 | 29 | # Default rules for deployment. 30 | qnx: target.path = /tmp/$${TARGET}/bin 31 | else: unix:!android: target.path = /opt/$${TARGET}/bin 32 | !isEmpty(target.path): INSTALLS += target 33 | 34 | win32: RC_ICONS += countdown.ico 35 | 36 | RESOURCES += \ 37 | timer.qrc 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /QtTimer/Timer/Timer.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {10cbb270-ce66-4af7-b4e3-ebd5179181b6} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | false 41 | true 42 | false 43 | 0 44 | true 45 | true 46 | 0 47 | 8 48 | true 49 | false 50 | 1 51 | true 52 | true 53 | true 54 | *.md, *.MD, Makefile 55 | false 56 | true 57 | true 58 | 59 | 60 | 61 | ProjectExplorer.Project.PluginSettings 62 | 63 | 64 | true 65 | false 66 | true 67 | true 68 | true 69 | true 70 | 71 | 72 | 0 73 | true 74 | 75 | true 76 | true 77 | Builtin.DefaultTidyAndClazy 78 | 6 79 | 80 | 81 | 82 | true 83 | 84 | 85 | 86 | 87 | ProjectExplorer.Project.Target.0 88 | 89 | Desktop 90 | Desktop Qt 6.4.2 GCC 64bit 91 | Desktop Qt 6.4.2 GCC 64bit 92 | qt.qt6.642.gcc_64_kit 93 | 1 94 | 0 95 | 0 96 | 97 | 0 98 | /home/share/nfs/build/build-Timer-Desktop_Qt_6_4_2_GCC_64bit 99 | /home/share/nfs/build/build-Timer-Desktop_Qt_6_4_2_GCC_64bit 100 | 101 | 102 | true 103 | QtProjectManager.QMakeBuildStep 104 | false 105 | 106 | 107 | 108 | true 109 | Qt4ProjectManager.MakeStep 110 | 111 | 2 112 | Build 113 | Build 114 | ProjectExplorer.BuildSteps.Build 115 | 116 | 117 | 118 | true 119 | Qt4ProjectManager.MakeStep 120 | clean 121 | 122 | 1 123 | Clean 124 | Clean 125 | ProjectExplorer.BuildSteps.Clean 126 | 127 | 2 128 | false 129 | 130 | false 131 | 132 | Debug 133 | Qt4ProjectManager.Qt4BuildConfiguration 134 | 2 135 | 136 | 137 | /home/share/nfs/build/build-Timer-Desktop_Qt_6_4_2_GCC_64bit 138 | /home/share/nfs/build/build-Timer-Desktop_Qt_6_4_2_GCC_64bit 139 | 140 | 141 | true 142 | QtProjectManager.QMakeBuildStep 143 | false 144 | 145 | 146 | 147 | true 148 | Qt4ProjectManager.MakeStep 149 | 150 | 2 151 | Build 152 | Build 153 | ProjectExplorer.BuildSteps.Build 154 | 155 | 156 | 157 | true 158 | Qt4ProjectManager.MakeStep 159 | clean 160 | 161 | 1 162 | Clean 163 | Clean 164 | ProjectExplorer.BuildSteps.Clean 165 | 166 | 2 167 | false 168 | 169 | false 170 | 171 | Release 172 | Qt4ProjectManager.Qt4BuildConfiguration 173 | 0 174 | 0 175 | 176 | 177 | 0 178 | /home/share/nfs/build/build-Timer-Desktop_Qt_6_4_2_GCC_64bit 179 | /home/share/nfs/build/build-Timer-Desktop_Qt_6_4_2_GCC_64bit 180 | 181 | 182 | true 183 | QtProjectManager.QMakeBuildStep 184 | false 185 | 186 | 187 | 188 | true 189 | Qt4ProjectManager.MakeStep 190 | 191 | 2 192 | Build 193 | Build 194 | ProjectExplorer.BuildSteps.Build 195 | 196 | 197 | 198 | true 199 | Qt4ProjectManager.MakeStep 200 | clean 201 | 202 | 1 203 | Clean 204 | Clean 205 | ProjectExplorer.BuildSteps.Clean 206 | 207 | 2 208 | false 209 | 210 | false 211 | 212 | Profile 213 | Qt4ProjectManager.Qt4BuildConfiguration 214 | 0 215 | 0 216 | 0 217 | 218 | 3 219 | 220 | 221 | 0 222 | Deploy 223 | Deploy 224 | ProjectExplorer.BuildSteps.Deploy 225 | 226 | 1 227 | 228 | false 229 | ProjectExplorer.DefaultDeployConfiguration 230 | 231 | 1 232 | 233 | true 234 | true 235 | true 236 | 237 | 2 238 | 239 | Qt4ProjectManager.Qt4RunConfiguration:/home/lastsee/git/QtProject/QtTimer/Timer/Timer.pro 240 | /home/lastsee/git/QtProject/QtTimer/Timer/Timer.pro 241 | false 242 | true 243 | true 244 | false 245 | true 246 | /home/share/nfs/bin 247 | 248 | 1 249 | 250 | 251 | 252 | ProjectExplorer.Project.TargetCount 253 | 1 254 | 255 | 256 | ProjectExplorer.Project.Updater.FileVersion 257 | 22 258 | 259 | 260 | Version 261 | 22 262 | 263 | 264 | -------------------------------------------------------------------------------- /QtTimer/Timer/countdown.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtTimer/Timer/countdown.ico -------------------------------------------------------------------------------- /QtTimer/Timer/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | QApplication a(argc, argv); 13 | QIcon icon(":/countdown.ico"); 14 | Widget w; 15 | 16 | QMenu* menu = new QMenu(&w); 17 | QAction* openAction = new QAction("打开", menu); 18 | QAction* exitAction = new QAction("退出", menu); 19 | QSystemTrayIcon* trayIcon = new QSystemTrayIcon(&w); 20 | 21 | 22 | menu->addAction(openAction); 23 | menu->addAction(exitAction); 24 | 25 | trayIcon->setContextMenu(menu); 26 | trayIcon->setIcon(icon); 27 | trayIcon->show(); 28 | 29 | a.setWindowIcon(icon); 30 | 31 | w.show(); 32 | 33 | 34 | QObject::connect(exitAction, &QAction::triggered, [&a]() { 35 | a.quit(); 36 | }); 37 | 38 | QObject::connect(openAction, &QAction::triggered, [&w]() { 39 | w.show(); 40 | }); 41 | 42 | // 托盘图标双击事件 43 | QObject::connect(trayIcon, &QSystemTrayIcon::activated, [&w](QSystemTrayIcon::ActivationReason reason) { 44 | if (reason == QSystemTrayIcon::DoubleClick) { 45 | w.show(); // 双击托盘,显示窗口 46 | } 47 | }); 48 | 49 | return a.exec(); 50 | } 51 | -------------------------------------------------------------------------------- /QtTimer/Timer/timer.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | countdown.ico 4 | 5 | 6 | -------------------------------------------------------------------------------- /QtTimer/Timer/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | Widget::Widget(QWidget *parent) 10 | : QWidget(parent) 11 | , ui(new Ui::Widget) 12 | { 13 | ui->setupUi(this); 14 | this->setWindowTitle("倒计时"); 15 | 16 | this->setWindowFlags(Qt::WindowStaysOnTopHint); 17 | 18 | 19 | timer_ = new QTimer(this); 20 | dialog_ = new QDialog(this); 21 | 22 | auto btn = new QPushButton(dialog_); 23 | btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 24 | QFont font = btn->font(); 25 | font.setPixelSize(50); 26 | btn->setFont(font); 27 | 28 | QHBoxLayout *lay = new QHBoxLayout; 29 | lay->addWidget(btn); 30 | 31 | dialog_->setLayout(lay); 32 | 33 | 34 | connect(btn, &QPushButton::clicked, dialog_, &QDialog::hide); 35 | 36 | 37 | connect(timer_,&QTimer::timeout, [=](){ 38 | if (--count_ <= 0) { 39 | QString taskname = ui->taskname->text(); 40 | btn->setText(taskname); 41 | 42 | dialog_->showFullScreen(); 43 | on_stop_clicked(); 44 | return; 45 | } 46 | 47 | int hh = count_ / 3600; 48 | int mm = count_ % 3600 / 60; 49 | int ss = count_ % 60; 50 | 51 | ui->countdown->setText(QString::asprintf("%02d:%02d:%02d", hh, mm, ss)); 52 | }); 53 | 54 | } 55 | 56 | Widget::~Widget() 57 | { 58 | delete ui; 59 | } 60 | 61 | void Widget::closeEvent(QCloseEvent *event) 62 | { 63 | event->ignore(); 64 | this->hide(); 65 | } 66 | 67 | void Widget::on_start_clicked() 68 | { 69 | if (timer_->isActive()) return; 70 | int hh{},mm{},ss{}; 71 | 72 | if (!ui->hhcount->text().isEmpty()) hh = ui->hhcount->text().toInt(); 73 | if (!ui->mmcount->text().isEmpty()) mm = ui->mmcount->text().toInt(); 74 | if (!ui->sscount->text().isEmpty()) ss = ui->sscount->text().toInt(); 75 | ui->countdown->setText(QString::asprintf("%02d:%02d:%02d", hh, mm, ss)); 76 | 77 | count_ = hh * 3600 + mm * 60 + ss; 78 | 79 | timer_->start(1000); 80 | } 81 | 82 | 83 | void Widget::on_stop_clicked() 84 | { 85 | timer_->stop(); 86 | count_ = 0; 87 | int hh{}, mm{}, ss{}; 88 | ui->countdown->setText(QString::asprintf("%02d:%02d:%02d", hh, mm, ss)); 89 | } 90 | 91 | -------------------------------------------------------------------------------- /QtTimer/Timer/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | 12 | class QTimer; 13 | 14 | class Widget : public QWidget 15 | { 16 | Q_OBJECT 17 | 18 | 19 | QTimer *timer_{}; 20 | int count_{}; 21 | QDialog *dialog_{}; 22 | 23 | public: 24 | Widget(QWidget *parent = nullptr); 25 | ~Widget(); 26 | 27 | 28 | protected: 29 | virtual void closeEvent(QCloseEvent *event); 30 | 31 | private slots: 32 | 33 | void on_start_clicked(); 34 | void on_stop_clicked(); 35 | 36 | private: 37 | Ui::Widget *ui; 38 | }; 39 | #endif // WIDGET_H 40 | -------------------------------------------------------------------------------- /QtTimer/Timer/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 任务名称 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 0 44 | 45 | 46 | 0 47 | 48 | 49 | 0 50 | 51 | 52 | 0 53 | 54 | 55 | 0 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 59 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 0 79 | 80 | 81 | 0 82 | 83 | 84 | 0 85 | 86 | 87 | 0 88 | 89 | 90 | 0 91 | 92 | 93 | 94 | 95 | : 96 | 97 | 98 | 99 | 100 | 101 | 102 | 59 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 0 114 | 115 | 116 | 0 117 | 118 | 119 | 0 120 | 121 | 122 | 0 123 | 124 | 125 | 0 126 | 127 | 128 | 129 | 130 | : 131 | 132 | 133 | 134 | 135 | 136 | 137 | 59 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 倒计时 154 | 155 | 156 | Qt::AlignCenter 157 | 158 | 159 | 160 | 161 | 162 | 163 | 00:00:00 164 | 165 | 166 | Qt::AlignCenter 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 停止 180 | 181 | 182 | 183 | 184 | 185 | 186 | 开始 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | -------------------------------------------------------------------------------- /QtTimer/mytimer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtTimer/mytimer.gif -------------------------------------------------------------------------------- /QtVirtualKeyboard/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Haijie He 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/README.md: -------------------------------------------------------------------------------- 1 | # QtProject 2 | 自定义 qt 控件 3 | 工程: 4 | 1. 一个使用 QWiget 开发的 QT 虚拟键盘,理论上可以适用所有的 qt 版本,本项目使用数据库 sqlite3 来实现拼音词组。 解决需求:嵌入式或者其他场景需要用到 qt 键盘来完成汉字词组的输入,并且无法使用 qml。 5 | ![qt虚拟键盘演示](https://github.com/seejv/QtProject/blob/QtVirtualKeyboard/useKeyBoard_Demo/keyboard_show-how.gif) 6 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/makeChinesePY_db/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | /* 12 | QQPinYin.txt 有部分重复,因此创建db时会报错 13 | ";"作为结束符号 ni,hao; 14 | ni; 15 | 关于词组,对照,可以到网络上去找,然后自己提取,最后再制成对应的数据库 16 | */ 17 | 18 | 19 | void creatWordGroup(QString PinYin_txt, QString sqlpath) 20 | { 21 | QFile file(PinYin_txt); 22 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) 23 | return; 24 | 25 | //添加数据库驱动 26 | QSqlDatabase db; 27 | if(QSqlDatabase::contains("my_sqlite")) 28 | db = QSqlDatabase::database("my_sqlite"); 29 | else 30 | db = QSqlDatabase::addDatabase("QSQLITE", "my_sqlite"); 31 | 32 | //设置数据库名称 33 | // db.setDatabaseName(sqlpath); 34 | db.setDatabaseName(sqlpath);//:memory: 35 | 36 | //打开数据库 37 | if(!db.open()) 38 | { 39 | return; 40 | } 41 | 42 | QStringList list{}; 43 | QStringList listPY{}; 44 | QString command{}; 45 | QTextStream in(&file); 46 | QString savsql("INSERT INTO WordAndGroup(PinYin, Chinese)"); 47 | // QString savsql("INSERT INTO WordGroup(PinYin, Chinese)"); 48 | //以下执行相关sql语句 49 | QSqlQuery query(db); 50 | 51 | //新建 PinyinChinese 表,id设置为主键,还有一个 Chinese 项 52 | command = "create table if not exists WordAndGroup(PinYin TEXT NOT NULL, Chinese TEXT NOT NULL, PRIMARY KEY(PinYin, Chinese))"; 53 | // command = "create table if not exists WordGroup(PinYin TEXT NOT NULL, Chinese TEXT NOT NULL, PRIMARY KEY(PinYin, Chinese))"; 54 | if(!query.exec(command)) 55 | { 56 | qDebug()<<__func__<setupUi(this); 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | } 25 | 26 | MainWindow::~MainWindow() 27 | { 28 | delete ui; 29 | } 30 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/makeChinesePY_db/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class MainWindow; 8 | } 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/makeChinesePY_db/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | MainWindow 3 | 4 | 5 | 6 | 0 7 | 0 8 | 400 9 | 300 10 | 11 | 12 | 13 | MainWindow 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/makeChinesePY_db/makeChinesePY_db.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-01-23T16:03:01 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | #QT += coregui sql 9 | QT += core sql 10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 11 | 12 | TARGET = makeDict 13 | TEMPLATE = app 14 | 15 | # The following define makes your compiler emit warnings if you use 16 | # any feature of Qt which has been marked as deprecated (the exact warnings 17 | # depend on your compiler). Please consult the documentation of the 18 | # deprecated API in order to know how to port your code away from it. 19 | DEFINES += QT_DEPRECATED_WARNINGS 20 | 21 | # You can also make your code fail to compile if you use deprecated APIs. 22 | # In order to do so, uncomment the following line. 23 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 24 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 25 | 26 | CONFIG += c++11 27 | 28 | SOURCES += \ 29 | main.cpp \ 30 | mainwindow.cpp 31 | 32 | HEADERS += \ 33 | mainwindow.h 34 | 35 | FORMS += \ 36 | mainwindow.ui 37 | 38 | # Default rules for deployment. 39 | qnx: target.path = /tmp/$${TARGET}/bin 40 | else: unix:!android: target.path = /opt/$${TARGET}/bin 41 | !isEmpty(target.path): INSTALLS += target 42 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/makeChinesePY_db/readme.cn: -------------------------------------------------------------------------------- 1 | 这里的话由于原来的制作的拼音词组已经被弄丢了,因此,这里仅仅提供一个生成带汉字词组的数据库 2 | 关于对应关系在代码中可以详细得知 3 | 关于 拼音 - 汉字 这样的对应表,大家可以到网络上去找对应的词库,例如 qq 词库,语料库在线,等等 4 | 地方下载需要的辞典,然后再自己提取需要的内容,最终再生成数据库 5 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/.gitigore: -------------------------------------------------------------------------------- 1 | *.o 2 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_CXX.QT_COMPILER_STDCXX = 199711L 2 | QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 5 3 | QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 4 4 | QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0 5 | QMAKE_CXX.COMPILER_MACROS = \ 6 | QT_COMPILER_STDCXX \ 7 | QMAKE_GCC_MAJOR_VERSION \ 8 | QMAKE_GCC_MINOR_VERSION \ 9 | QMAKE_GCC_PATCH_VERSION 10 | QMAKE_CXX.INCDIRS = \ 11 | /usr/include/c++/5 \ 12 | /usr/include/x86_64-linux-gnu/c++/5 \ 13 | /usr/include/c++/5/backward \ 14 | /usr/lib/gcc/x86_64-linux-gnu/5/include \ 15 | /usr/local/include \ 16 | /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed \ 17 | /usr/include/x86_64-linux-gnu \ 18 | /usr/include 19 | QMAKE_CXX.LIBDIRS = \ 20 | /usr/lib/gcc/x86_64-linux-gnu/5 \ 21 | /usr/lib/x86_64-linux-gnu \ 22 | /usr/lib \ 23 | /lib/x86_64-linux-gnu \ 24 | /lib 25 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/keyboard_show-how.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/keyboard_show-how.gif -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "virtualkeyboard_hasQSQLITE/virtualkeyboard.h" 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | 10 | auto keyboard = VirtualKeyBoard::getKeyboard(); 11 | keyboard->setGeometry(300, 200, 432, 185); 12 | keyboard->init("virtualkeyboard_hasQSQLITE/Resource/ChinesePY.db"); 13 | 14 | auto le = new QLineEdit(nullptr); 15 | le->setGeometry(100, 0, 100,50); 16 | le->show(); 17 | le = new QLineEdit(nullptr); 18 | le->setGeometry(100, 200, 100,50); 19 | 20 | keyboard->show(); 21 | le->show(); 22 | 23 | 24 | return a.exec(); 25 | } 26 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/moc_predefs.h: -------------------------------------------------------------------------------- 1 | #define __SSP_STRONG__ 3 2 | #define __DBL_MIN_EXP__ (-1021) 3 | #define __cpp_attributes 200809 4 | #define __UINT_LEAST16_MAX__ 0xffff 5 | #define __ATOMIC_ACQUIRE 2 6 | #define __FLT_MIN__ 1.17549435082228750797e-38F 7 | #define __GCC_IEC_559_COMPLEX 2 8 | #define __UINT_LEAST8_TYPE__ unsigned char 9 | #define __SIZEOF_FLOAT80__ 16 10 | #define __INTMAX_C(c) c ## L 11 | #define __CHAR_BIT__ 8 12 | #define __UINT8_MAX__ 0xff 13 | #define __WINT_MAX__ 0xffffffffU 14 | #define __cpp_static_assert 200410 15 | #define __ORDER_LITTLE_ENDIAN__ 1234 16 | #define __SIZE_MAX__ 0xffffffffffffffffUL 17 | #define __WCHAR_MAX__ 0x7fffffff 18 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1 19 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1 20 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 21 | #define __DBL_DENORM_MIN__ double(4.94065645841246544177e-324L) 22 | #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 23 | #define __GCC_ATOMIC_CHAR_LOCK_FREE 2 24 | #define __GCC_IEC_559 2 25 | #define __FLT_EVAL_METHOD__ 0 26 | #define __unix__ 1 27 | #define __cpp_binary_literals 201304 28 | #define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 29 | #define __x86_64 1 30 | #define __cpp_variadic_templates 200704 31 | #define __UINT_FAST64_MAX__ 0xffffffffffffffffUL 32 | #define __SIG_ATOMIC_TYPE__ int 33 | #define __DBL_MIN_10_EXP__ (-307) 34 | #define __FINITE_MATH_ONLY__ 0 35 | #define __GNUC_PATCHLEVEL__ 0 36 | #define __UINT_FAST8_MAX__ 0xff 37 | #define __has_include(STR) __has_include__(STR) 38 | #define __DEC64_MAX_EXP__ 385 39 | #define __INT8_C(c) c 40 | #define __UINT_LEAST64_MAX__ 0xffffffffffffffffUL 41 | #define __SHRT_MAX__ 0x7fff 42 | #define __LDBL_MAX__ 1.18973149535723176502e+4932L 43 | #define __UINT_LEAST8_MAX__ 0xff 44 | #define __GCC_ATOMIC_BOOL_LOCK_FREE 2 45 | #define __UINTMAX_TYPE__ long unsigned int 46 | #define __linux 1 47 | #define __DEC32_EPSILON__ 1E-6DF 48 | #define __OPTIMIZE__ 1 49 | #define __unix 1 50 | #define __UINT32_MAX__ 0xffffffffU 51 | #define __GXX_EXPERIMENTAL_CXX0X__ 1 52 | #define __LDBL_MAX_EXP__ 16384 53 | #define __WINT_MIN__ 0U 54 | #define __linux__ 1 55 | #define __SCHAR_MAX__ 0x7f 56 | #define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1) 57 | #define __INT64_C(c) c ## L 58 | #define __DBL_DIG__ 15 59 | #define __GCC_ATOMIC_POINTER_LOCK_FREE 2 60 | #define _FORTIFY_SOURCE 2 61 | #define __SIZEOF_INT__ 4 62 | #define __SIZEOF_POINTER__ 8 63 | #define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 64 | #define __USER_LABEL_PREFIX__ 65 | #define __STDC_HOSTED__ 1 66 | #define __LDBL_HAS_INFINITY__ 1 67 | #define __FLT_EPSILON__ 1.19209289550781250000e-7F 68 | #define __GXX_WEAK__ 1 69 | #define __LDBL_MIN__ 3.36210314311209350626e-4932L 70 | #define __DEC32_MAX__ 9.999999E96DF 71 | #define __INT32_MAX__ 0x7fffffff 72 | #define __SIZEOF_LONG__ 8 73 | #define __STDC_IEC_559__ 1 74 | #define __STDC_ISO_10646__ 201505L 75 | #define __UINT16_C(c) c 76 | #define __DECIMAL_DIG__ 21 77 | #define __gnu_linux__ 1 78 | #define __has_include_next(STR) __has_include_next__(STR) 79 | #define __LDBL_HAS_QUIET_NAN__ 1 80 | #define __GNUC__ 5 81 | #define __GXX_RTTI 1 82 | #define __MMX__ 1 83 | #define __cpp_delegating_constructors 200604 84 | #define __FLT_HAS_DENORM__ 1 85 | #define __SIZEOF_LONG_DOUBLE__ 16 86 | #define __BIGGEST_ALIGNMENT__ 16 87 | #define __STDC_UTF_16__ 1 88 | #define __DBL_MAX__ double(1.79769313486231570815e+308L) 89 | #define __cpp_raw_strings 200710 90 | #define __INT_FAST32_MAX__ 0x7fffffffffffffffL 91 | #define __DBL_HAS_INFINITY__ 1 92 | #define __INT64_MAX__ 0x7fffffffffffffffL 93 | #define __DEC32_MIN_EXP__ (-94) 94 | #define __INT_FAST16_TYPE__ long int 95 | #define __LDBL_HAS_DENORM__ 1 96 | #define __cplusplus 201103L 97 | #define __cpp_ref_qualifiers 200710 98 | #define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL 99 | #define __INT_LEAST32_MAX__ 0x7fffffff 100 | #define __DEC32_MIN__ 1E-95DF 101 | #define __DEPRECATED 1 102 | #define __DBL_MAX_EXP__ 1024 103 | #define __DEC128_EPSILON__ 1E-33DL 104 | #define __SSE2_MATH__ 1 105 | #define __ATOMIC_HLE_RELEASE 131072 106 | #define __PTRDIFF_MAX__ 0x7fffffffffffffffL 107 | #define __amd64 1 108 | #define __STDC_NO_THREADS__ 1 109 | #define __ATOMIC_HLE_ACQUIRE 65536 110 | #define __GNUG__ 5 111 | #define __LONG_LONG_MAX__ 0x7fffffffffffffffLL 112 | #define __SIZEOF_SIZE_T__ 8 113 | #define __cpp_rvalue_reference 200610 114 | #define __cpp_nsdmi 200809 115 | #define __SIZEOF_WINT_T__ 4 116 | #define __cpp_initializer_lists 200806 117 | #define __GCC_HAVE_DWARF2_CFI_ASM 1 118 | #define __GXX_ABI_VERSION 1009 119 | #define __FLT_MIN_EXP__ (-125) 120 | #define __cpp_lambdas 200907 121 | #define __INT_FAST64_TYPE__ long int 122 | #define __DBL_MIN__ double(2.22507385850720138309e-308L) 123 | #define __LP64__ 1 124 | #define __DECIMAL_BID_FORMAT__ 1 125 | #define __DEC128_MIN__ 1E-6143DL 126 | #define __REGISTER_PREFIX__ 127 | #define __UINT16_MAX__ 0xffff 128 | #define __DBL_HAS_DENORM__ 1 129 | #define __UINT8_TYPE__ unsigned char 130 | #define __FLT_MANT_DIG__ 24 131 | #define __VERSION__ "5.4.0 20160609" 132 | #define __UINT64_C(c) c ## UL 133 | #define __cpp_unicode_characters 200704 134 | #define _STDC_PREDEF_H 1 135 | #define __GCC_ATOMIC_INT_LOCK_FREE 2 136 | #define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__ 137 | #define __STDC_IEC_559_COMPLEX__ 1 138 | #define __INT32_C(c) c 139 | #define __DEC64_EPSILON__ 1E-15DD 140 | #define __ORDER_PDP_ENDIAN__ 3412 141 | #define __DEC128_MIN_EXP__ (-6142) 142 | #define __INT_FAST32_TYPE__ long int 143 | #define __UINT_LEAST16_TYPE__ short unsigned int 144 | #define unix 1 145 | #define __INT16_MAX__ 0x7fff 146 | #define __cpp_rtti 199711 147 | #define __SIZE_TYPE__ long unsigned int 148 | #define __UINT64_MAX__ 0xffffffffffffffffUL 149 | #define __INT8_TYPE__ signed char 150 | #define __ELF__ 1 151 | #define __FLT_RADIX__ 2 152 | #define __INT_LEAST16_TYPE__ short int 153 | #define __LDBL_EPSILON__ 1.08420217248550443401e-19L 154 | #define __UINTMAX_C(c) c ## UL 155 | #define __GLIBCXX_BITSIZE_INT_N_0 128 156 | #define __k8 1 157 | #define __SIG_ATOMIC_MAX__ 0x7fffffff 158 | #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 159 | #define __SIZEOF_PTRDIFF_T__ 8 160 | #define __x86_64__ 1 161 | #define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF 162 | #define __INT_FAST16_MAX__ 0x7fffffffffffffffL 163 | #define __UINT_FAST32_MAX__ 0xffffffffffffffffUL 164 | #define __UINT_LEAST64_TYPE__ long unsigned int 165 | #define __FLT_HAS_QUIET_NAN__ 1 166 | #define __FLT_MAX_10_EXP__ 38 167 | #define __LONG_MAX__ 0x7fffffffffffffffL 168 | #define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL 169 | #define __FLT_HAS_INFINITY__ 1 170 | #define __cpp_unicode_literals 200710 171 | #define __UINT_FAST16_TYPE__ long unsigned int 172 | #define __DEC64_MAX__ 9.999999999999999E384DD 173 | #define __CHAR16_TYPE__ short unsigned int 174 | #define __PRAGMA_REDEFINE_EXTNAME 1 175 | #define __INT_LEAST16_MAX__ 0x7fff 176 | #define __DEC64_MANT_DIG__ 16 177 | #define __UINT_LEAST32_MAX__ 0xffffffffU 178 | #define __GCC_ATOMIC_LONG_LOCK_FREE 2 179 | #define __INT_LEAST64_TYPE__ long int 180 | #define __INT16_TYPE__ short int 181 | #define __INT_LEAST8_TYPE__ signed char 182 | #define __DEC32_MAX_EXP__ 97 183 | #define __INT_FAST8_MAX__ 0x7f 184 | #define __INTPTR_MAX__ 0x7fffffffffffffffL 185 | #define linux 1 186 | #define __cpp_range_based_for 200907 187 | #define __SSE2__ 1 188 | #define __EXCEPTIONS 1 189 | #define __LDBL_MANT_DIG__ 64 190 | #define __DBL_HAS_QUIET_NAN__ 1 191 | #define __SIG_ATOMIC_MIN__ (-__SIG_ATOMIC_MAX__ - 1) 192 | #define __code_model_small__ 1 193 | #define __k8__ 1 194 | #define __INTPTR_TYPE__ long int 195 | #define __UINT16_TYPE__ short unsigned int 196 | #define __WCHAR_TYPE__ int 197 | #define __SIZEOF_FLOAT__ 4 198 | #define __UINTPTR_MAX__ 0xffffffffffffffffUL 199 | #define __DEC64_MIN_EXP__ (-382) 200 | #define __cpp_decltype 200707 201 | #define __INT_FAST64_MAX__ 0x7fffffffffffffffL 202 | #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 203 | #define __FLT_DIG__ 6 204 | #define __UINT_FAST64_TYPE__ long unsigned int 205 | #define __INT_MAX__ 0x7fffffff 206 | #define __amd64__ 1 207 | #define __INT64_TYPE__ long int 208 | #define __FLT_MAX_EXP__ 128 209 | #define __ORDER_BIG_ENDIAN__ 4321 210 | #define __DBL_MANT_DIG__ 53 211 | #define __cpp_inheriting_constructors 200802 212 | #define __SIZEOF_FLOAT128__ 16 213 | #define __INT_LEAST64_MAX__ 0x7fffffffffffffffL 214 | #define __DEC64_MIN__ 1E-383DD 215 | #define __WINT_TYPE__ unsigned int 216 | #define __UINT_LEAST32_TYPE__ unsigned int 217 | #define __SIZEOF_SHORT__ 2 218 | #define __SSE__ 1 219 | #define __LDBL_MIN_EXP__ (-16381) 220 | #define __INT_LEAST8_MAX__ 0x7f 221 | #define __SIZEOF_INT128__ 16 222 | #define __LDBL_MAX_10_EXP__ 4932 223 | #define __ATOMIC_RELAXED 0 224 | #define __DBL_EPSILON__ double(2.22044604925031308085e-16L) 225 | #define _LP64 1 226 | #define __UINT8_C(c) c 227 | #define __INT_LEAST32_TYPE__ int 228 | #define __SIZEOF_WCHAR_T__ 4 229 | #define __UINT64_TYPE__ long unsigned int 230 | #define __INT_FAST8_TYPE__ signed char 231 | #define __GNUC_STDC_INLINE__ 1 232 | #define __DBL_DECIMAL_DIG__ 17 233 | #define __STDC_UTF_32__ 1 234 | #define __FXSR__ 1 235 | #define __DEC_EVAL_METHOD__ 2 236 | #define __cpp_runtime_arrays 198712 237 | #define __UINT32_C(c) c ## U 238 | #define __INTMAX_MAX__ 0x7fffffffffffffffL 239 | #define __cpp_alias_templates 200704 240 | #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ 241 | #define __FLT_DENORM_MIN__ 1.40129846432481707092e-45F 242 | #define __INT8_MAX__ 0x7f 243 | #define __UINT_FAST32_TYPE__ long unsigned int 244 | #define __CHAR32_TYPE__ unsigned int 245 | #define __FLT_MAX__ 3.40282346638528859812e+38F 246 | #define __cpp_constexpr 200704 247 | #define __INT32_TYPE__ int 248 | #define __SIZEOF_DOUBLE__ 8 249 | #define __cpp_exceptions 199711 250 | #define __INTMAX_TYPE__ long int 251 | #define __DEC128_MAX_EXP__ 6145 252 | #define __ATOMIC_CONSUME 1 253 | #define __GNUC_MINOR__ 4 254 | #define __GLIBCXX_TYPE_INT_N_0 __int128 255 | #define __UINTMAX_MAX__ 0xffffffffffffffffUL 256 | #define __DEC32_MANT_DIG__ 7 257 | #define __DBL_MAX_10_EXP__ 308 258 | #define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L 259 | #define __INT16_C(c) c 260 | #define __STDC__ 1 261 | #define __PTRDIFF_TYPE__ long int 262 | #define __ATOMIC_SEQ_CST 5 263 | #define __UINT32_TYPE__ unsigned int 264 | #define __UINTPTR_TYPE__ long unsigned int 265 | #define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD 266 | #define __DEC128_MANT_DIG__ 34 267 | #define __LDBL_MIN_10_EXP__ (-4931) 268 | #define __SSE_MATH__ 1 269 | #define __SIZEOF_LONG_LONG__ 8 270 | #define __cpp_user_defined_literals 200809 271 | #define __GCC_ATOMIC_LLONG_LOCK_FREE 2 272 | #define __LDBL_DIG__ 18 273 | #define __FLT_DECIMAL_DIG__ 9 274 | #define __UINT_FAST16_MAX__ 0xffffffffffffffffUL 275 | #define __FLT_MIN_10_EXP__ (-37) 276 | #define __GCC_ATOMIC_SHORT_LOCK_FREE 2 277 | #define __UINT_FAST8_TYPE__ unsigned char 278 | #define _GNU_SOURCE 1 279 | #define __ATOMIC_ACQ_REL 4 280 | #define __ATOMIC_RELEASE 3 281 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/moc_virtualkeyboard.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Meta object code from reading C++ file 'virtualkeyboard.h' 3 | ** 4 | ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.12.8) 5 | ** 6 | ** WARNING! All changes made in this file will be lost! 7 | *****************************************************************************/ 8 | 9 | #include "virtualkeyboard_hasQSQLITE/virtualkeyboard.h" 10 | #include 11 | #include 12 | #if !defined(Q_MOC_OUTPUT_REVISION) 13 | #error "The header file 'virtualkeyboard.h' doesn't include ." 14 | #elif Q_MOC_OUTPUT_REVISION != 67 15 | #error "This file was generated using the moc from 5.12.8. It" 16 | #error "cannot be used with the include files from this version of Qt." 17 | #error "(The moc has changed too much.)" 18 | #endif 19 | 20 | QT_BEGIN_MOC_NAMESPACE 21 | QT_WARNING_PUSH 22 | QT_WARNING_DISABLE_DEPRECATED 23 | struct qt_meta_stringdata_VirtualKeyBoard_t { 24 | QByteArrayData data[18]; 25 | char stringdata0[208]; 26 | }; 27 | #define QT_MOC_LITERAL(idx, ofs, len) \ 28 | Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ 29 | qptrdiff(offsetof(qt_meta_stringdata_VirtualKeyBoard_t, stringdata0) + ofs \ 30 | - idx * sizeof(QByteArrayData)) \ 31 | ) 32 | static const qt_meta_stringdata_VirtualKeyBoard_t qt_meta_stringdata_VirtualKeyBoard = { 33 | { 34 | QT_MOC_LITERAL(0, 0, 15), // "VirtualKeyBoard" 35 | QT_MOC_LITERAL(1, 16, 24), // "changedOutSideTextSignal" 36 | QT_MOC_LITERAL(2, 41, 0), // "" 37 | QT_MOC_LITERAL(3, 42, 4), // "text" 38 | QT_MOC_LITERAL(4, 47, 7), // "objName" 39 | QT_MOC_LITERAL(5, 55, 21), // "setDefaultColorSignal" 40 | QT_MOC_LITERAL(6, 77, 11), // "showChinese" 41 | QT_MOC_LITERAL(7, 89, 3), // "key" 42 | QT_MOC_LITERAL(8, 93, 21), // "QMap" 43 | QT_MOC_LITERAL(9, 115, 16), // "chinese_list_map" 44 | QT_MOC_LITERAL(10, 132, 17), // "recKeyClickedSlot" 45 | QT_MOC_LITERAL(11, 150, 13), // "selectChinese" 46 | QT_MOC_LITERAL(12, 164, 16), // "focusChangedSlot" 47 | QT_MOC_LITERAL(13, 181, 8), // "QWidget*" 48 | QT_MOC_LITERAL(14, 190, 3), // "old" 49 | QT_MOC_LITERAL(15, 194, 3), // "now" 50 | QT_MOC_LITERAL(16, 198, 4), // "show" 51 | QT_MOC_LITERAL(17, 203, 4) // "hide" 52 | 53 | }, 54 | "VirtualKeyBoard\0changedOutSideTextSignal\0" 55 | "\0text\0objName\0setDefaultColorSignal\0" 56 | "showChinese\0key\0QMap\0" 57 | "chinese_list_map\0recKeyClickedSlot\0" 58 | "selectChinese\0focusChangedSlot\0QWidget*\0" 59 | "old\0now\0show\0hide" 60 | }; 61 | #undef QT_MOC_LITERAL 62 | 63 | static const uint qt_meta_data_VirtualKeyBoard[] = { 64 | 65 | // content: 66 | 8, // revision 67 | 0, // classname 68 | 0, 0, // classinfo 69 | 8, 14, // methods 70 | 0, 0, // properties 71 | 0, 0, // enums/sets 72 | 0, 0, // constructors 73 | 0, // flags 74 | 2, // signalCount 75 | 76 | // signals: name, argc, parameters, tag, flags 77 | 1, 2, 54, 2, 0x06 /* Public */, 78 | 5, 0, 59, 2, 0x06 /* Public */, 79 | 80 | // slots: name, argc, parameters, tag, flags 81 | 6, 2, 60, 2, 0x08 /* Private */, 82 | 10, 0, 65, 2, 0x08 /* Private */, 83 | 11, 0, 66, 2, 0x08 /* Private */, 84 | 12, 2, 67, 2, 0x08 /* Private */, 85 | 16, 0, 72, 2, 0x0a /* Public */, 86 | 17, 0, 73, 2, 0x0a /* Public */, 87 | 88 | // signals: parameters 89 | QMetaType::Void, QMetaType::QString, QMetaType::QString, 3, 4, 90 | QMetaType::Void, 91 | 92 | // slots: parameters 93 | QMetaType::Void, QMetaType::QString, 0x80000000 | 8, 7, 9, 94 | QMetaType::Void, 95 | QMetaType::Void, 96 | QMetaType::Void, 0x80000000 | 13, 0x80000000 | 13, 14, 15, 97 | QMetaType::Void, 98 | QMetaType::Void, 99 | 100 | 0 // eod 101 | }; 102 | 103 | void VirtualKeyBoard::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 104 | { 105 | if (_c == QMetaObject::InvokeMetaMethod) { 106 | auto *_t = static_cast(_o); 107 | Q_UNUSED(_t) 108 | switch (_id) { 109 | case 0: _t->changedOutSideTextSignal((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break; 110 | case 1: _t->setDefaultColorSignal(); break; 111 | case 2: _t->showChinese((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QMap(*)>(_a[2]))); break; 112 | case 3: _t->recKeyClickedSlot(); break; 113 | case 4: _t->selectChinese(); break; 114 | case 5: _t->focusChangedSlot((*reinterpret_cast< QWidget*(*)>(_a[1])),(*reinterpret_cast< QWidget*(*)>(_a[2]))); break; 115 | case 6: _t->show(); break; 116 | case 7: _t->hide(); break; 117 | default: ; 118 | } 119 | } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { 120 | switch (_id) { 121 | default: *reinterpret_cast(_a[0]) = -1; break; 122 | case 5: 123 | switch (*reinterpret_cast(_a[1])) { 124 | default: *reinterpret_cast(_a[0]) = -1; break; 125 | case 1: 126 | case 0: 127 | *reinterpret_cast(_a[0]) = qRegisterMetaType< QWidget* >(); break; 128 | } 129 | break; 130 | } 131 | } else if (_c == QMetaObject::IndexOfMethod) { 132 | int *result = reinterpret_cast(_a[0]); 133 | { 134 | using _t = void (VirtualKeyBoard::*)(const QString & , const QString & ); 135 | if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&VirtualKeyBoard::changedOutSideTextSignal)) { 136 | *result = 0; 137 | return; 138 | } 139 | } 140 | { 141 | using _t = void (VirtualKeyBoard::*)(); 142 | if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&VirtualKeyBoard::setDefaultColorSignal)) { 143 | *result = 1; 144 | return; 145 | } 146 | } 147 | } 148 | } 149 | 150 | QT_INIT_METAOBJECT const QMetaObject VirtualKeyBoard::staticMetaObject = { { 151 | &QWidget::staticMetaObject, 152 | qt_meta_stringdata_VirtualKeyBoard.data, 153 | qt_meta_data_VirtualKeyBoard, 154 | qt_static_metacall, 155 | nullptr, 156 | nullptr 157 | } }; 158 | 159 | 160 | const QMetaObject *VirtualKeyBoard::metaObject() const 161 | { 162 | return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; 163 | } 164 | 165 | void *VirtualKeyBoard::qt_metacast(const char *_clname) 166 | { 167 | if (!_clname) return nullptr; 168 | if (!strcmp(_clname, qt_meta_stringdata_VirtualKeyBoard.stringdata0)) 169 | return static_cast(this); 170 | return QWidget::qt_metacast(_clname); 171 | } 172 | 173 | int VirtualKeyBoard::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 174 | { 175 | _id = QWidget::qt_metacall(_c, _id, _a); 176 | if (_id < 0) 177 | return _id; 178 | if (_c == QMetaObject::InvokeMetaMethod) { 179 | if (_id < 8) 180 | qt_static_metacall(this, _c, _id, _a); 181 | _id -= 8; 182 | } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { 183 | if (_id < 8) 184 | qt_static_metacall(this, _c, _id, _a); 185 | _id -= 8; 186 | } 187 | return _id; 188 | } 189 | 190 | // SIGNAL 0 191 | void VirtualKeyBoard::changedOutSideTextSignal(const QString & _t1, const QString & _t2) 192 | { 193 | void *_a[] = { nullptr, const_cast(reinterpret_cast(&_t1)), const_cast(reinterpret_cast(&_t2)) }; 194 | QMetaObject::activate(this, &staticMetaObject, 0, _a); 195 | } 196 | 197 | // SIGNAL 1 198 | void VirtualKeyBoard::setDefaultColorSignal() 199 | { 200 | QMetaObject::activate(this, &staticMetaObject, 1, nullptr); 201 | } 202 | QT_WARNING_POP 203 | QT_END_MOC_NAMESPACE 204 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/useKeyBoard_Demo.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | include(virtualkeyboard_hasQSQLITE/virtualkeyboard.pri) 19 | 20 | 21 | 22 | SOURCES += \ 23 | main.cpp 24 | 25 | HEADERS += 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ChinesePY.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ChinesePY.db -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/Earth-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/Earth-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/back-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/back-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/keyboard-hide-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/keyboard-hide-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/left-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/left-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/right-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/right-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/shift-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/shift-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/triangle-outline-RGB210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/128x128没有使用/triangle-outline-RGB210.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/Earth-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/Earth-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/back-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/back-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/backspace-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/backspace-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/keyboard-hide-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/keyboard-hide-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/left-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/left-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/return-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/return-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/right-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/right-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/shift-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/shift-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/triangle-outline-RGB60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/ICON/triangle-outline-RGB60.png -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/VirtualKeyBoardResource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ICON/back-RGB60.png 4 | ICON/Earth-RGB60.png 5 | ICON/keyboard-hide-RGB60.png 6 | ICON/left-RGB60.png 7 | ICON/right-RGB60.png 8 | ICON/shift-RGB60.png 9 | ICON/triangle-outline-RGB60.png 10 | ICON/return-RGB60.png 11 | ICON/backspace-RGB60.png 12 | 13 | 14 | keyboard.qss 15 | 16 | 17 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/keyboard.qss: -------------------------------------------------------------------------------- 1 | /* 2 | font: 24pt "Ubuntu"; 3 | font: 75 24pt "Ubuntu";//加粗 4 | */ 5 | 6 | /* 7 | 8 | */ 9 | QWidget#VirtualKeyBoard 10 | { 11 | border:0px solid rgb(255,0,0); 12 | /* background:rgba(60,60,60,100%);*/ 13 | background:rgba(231,235,238,100%);/*设置背景透明(要求父类不为空,不然表现为黑块)*/ 14 | } 15 | 16 | /* 17 | 键盘输入区域 18 | */ 19 | QWidget#widget_key 20 | { 21 | border:0px; 22 | /* background:rgb(211,211,211);*/ 23 | /* border-image: url(:/image/background/tree_book.jpg);*/ 24 | /* border-image: url(:/image/background/sky_2.jpg);*/ 25 | /* border-image: url(:/image/background/sky_like.jpg);*/ 26 | /* border-image: url(:/image/background/dream.jpg);*/ 27 | } 28 | 29 | QPushButton 30 | { 31 | /* qproperty-minimumSize: 50px 50px;*/ 32 | /* qproperty-maximumSize: 50px 50px;*/ 33 | border-style:outset; 34 | 35 | font: 20pt "Ubuntu"; 36 | border:1px solid rgba(0,0,0,0%); 37 | border-radius:10px; 38 | color:rgb(0,0,0); 39 | background-color:rgb(255,255,255); 40 | } 41 | QPushButton:pressed 42 | { 43 | /* background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, 44 | stop: 0 #dadbde, stop: 1 #f6f7fa);*/ 45 | background-color:rgb(92,150,247); 46 | color:rgb(255,255,255); 47 | } 48 | 49 | QPushButton[text=""] 50 | { 51 | border:0px; 52 | color:rgba(0,0,0,0%); 53 | background-color:rgba(0,0,0,0%); 54 | } 55 | QPushButton[text=""]:pressed 56 | { 57 | } 58 | 59 | /*显示中文时输入的英文*/ 60 | QLabel#lb_display_text 61 | { 62 | /*font: 22pt "Ubuntu";*/ 63 | font: 22pt "Ubuntu"; 64 | border: 0px solid rgb(255,0,0); 65 | /* border-radius: 5px;*/ 66 | background:rgba(60,60,60,100%); 67 | color:rgb(210,210,210); 68 | } 69 | 70 | QLabel#lb_display_text[text=""] 71 | { 72 | background:rgba(0,0,0,0%); 73 | } 74 | 75 | /**********************第一行按钮*********************/ 76 | /* 77 | 专用来显示待选中文 78 | */ 79 | QWidget#widget_showChinese 80 | { 81 | border:0px; 82 | /* background:rgb(222,222,222);*/ 83 | /* qproperty-minimumSize: 9999px 50px;*/ 84 | qproperty-maximumSize: 9999px 50px; 85 | } 86 | 87 | 88 | /* 89 | 左切换待选汉字----------字符为空,则隐藏 90 | */ 91 | QPushButton#btn0_left 92 | { 93 | background-color:rgba(0,0,0,0%); 94 | } 95 | QPushButton#btn0_02 96 | { 97 | font: 14pt "Ubuntu"; 98 | background-color:rgba(0,0,0,0%); 99 | } 100 | QPushButton#btn0_03 101 | { 102 | font: 14pt "Ubuntu"; 103 | background-color:rgba(0,0,0,0%); 104 | } 105 | QPushButton#btn0_04 106 | { 107 | font: 14pt "Ubuntu"; 108 | background-color:rgba(0,0,0,0%); 109 | } 110 | QPushButton#btn0_05 111 | { 112 | font: 14pt "Ubuntu"; 113 | background-color:rgba(0,0,0,0%); 114 | } 115 | QPushButton#btn0_06 116 | { 117 | font: 14pt "Ubuntu"; 118 | background-color:rgba(0,0,0,0%); 119 | } 120 | QPushButton#btn0_07 121 | { 122 | font: 14pt "Ubuntu"; 123 | background-color:rgba(0,0,0,0%); 124 | } 125 | QPushButton#btn0_08 126 | { 127 | font: 14pt "Ubuntu"; 128 | background-color:rgba(0,0,0,0%); 129 | } 130 | QPushButton#btn0_09 131 | { 132 | font: 14pt "Ubuntu"; 133 | background-color:rgba(0,0,0,0%); 134 | } 135 | 136 | /* 137 | 右边切换待选汉字 138 | */ 139 | QPushButton#btn0_right 140 | { 141 | /* color:rgba(0,0,0,100%);*/ 142 | background-color:rgba(0,0,0,0%); 143 | } 144 | 145 | 146 | 147 | QPushButton#btn0_left:pressed 148 | { 149 | background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, 150 | stop: 0 #dadbde, stop: 1 #f6f7fa); 151 | } 152 | QPushButton#btn0_right:pressed 153 | { 154 | background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, 155 | stop: 0 #dadbde, stop: 1 #f6f7fa); 156 | } 157 | /**********************第二行按钮*********************/ 158 | /* 159 | 退格按钮 160 | */ 161 | QPushButton#btn1_backspace 162 | { 163 | color:rgba(0,0,0,0%); 164 | image:url(:/image/ICON/backspace-RGB60.png); 165 | /* padding:10px;*/ 166 | } 167 | /*** 168 | *******************第三行按钮*********************/ 169 | /* 170 | 回车按钮 171 | */ 172 | QPushButton#btn2_return[text="ok"] 173 | { 174 | color:rgba(0,0,0,0%); 175 | image:url(:/image/ICON/return-RGB60.png); 176 | } 177 | 178 | /**********************第四行按钮*********************/ 179 | /* 180 | 左SHIFT按钮 181 | */ 182 | QPushButton#btn3_Lshirt 183 | { 184 | color:rgba(0,0,0,0%); 185 | image:url(:/image/ICON/shift-RGB60.png); 186 | } 187 | QPushButton#btn3_Lshirt[text="Le"] 188 | { 189 | color:rgba(0,0,0,0%); 190 | image:url(:/image/ICON/left-RGB60.png); 191 | } 192 | /* 193 | 右SHIFT按钮 194 | */ 195 | QPushButton#btn3_Rshirt 196 | { 197 | color:rgba(0,0,0,0%); 198 | image:url(:/image/ICON/shift-RGB60.png); 199 | } 200 | QPushButton#btn3_Rshirt[text="Ri"] 201 | { 202 | color:rgba(0,0,0,0%); 203 | image:url(:/image/ICON/right-RGB60.png); 204 | } 205 | 206 | /**********************第五行按钮*********************/ 207 | /* 208 | 切换输入法按钮 209 | */ 210 | 211 | QPushButton#btn4_symbol[text="ABC"] 212 | { 213 | image: url(:/image/ICON/back-RGB60.png); 214 | /*qproperty-iconSize:5px 5px;*/ 215 | padding-top:10px; 216 | padding-bottom:10px; 217 | color:rgba(0,0,0,0%); 218 | background-color:rgba(0,0,0,0%); 219 | } 220 | 221 | QPushButton#btn4_switch 222 | { 223 | 224 | /*qproperty-iconSize:5px 5px;*/ 225 | 226 | color:rgba(0,0,0,0%); 227 | /* padding-top:10px; 228 | padding-bottom:10px;*/ 229 | image: url(:/image/ICON/Earth-RGB60.png); 230 | } 231 | 232 | /* 233 | 隐藏键盘按钮 234 | */ 235 | QPushButton#btn4_hide 236 | { 237 | color:rgba(0,0,0,0%); 238 | image: url(:/image/ICON/triangle-outline-RGB60.png); 239 | } 240 | 241 | 242 | 243 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seejv/QtProject/f3ebfa3093770b2be99a07db84ec1c62a3561fa9/QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/readme.txt -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/Resource/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | ICON/back-RGB60.png 4 | ICON/Earth-RGB60.png 5 | ICON/keyboard-hide-RGB60.png 6 | ICON/left-RGB60.png 7 | ICON/right-RGB60.png 8 | ICON/shift-RGB60.png 9 | ICON/triangle-outline-RGB60.png 10 | ICON/return-RGB60.png 11 | ICON/backspace-RGB60.png 12 | background/dream.jpg 13 | background/sky_2.jpg 14 | background/sky_like.jpg 15 | background/tree_book.jpg 16 | 17 | 18 | keyboard.qss 19 | 20 | 21 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/main.cpp: -------------------------------------------------------------------------------- 1 | #include "virtualkeyboard.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | void setStyleQss(QString qss_path) 7 | { 8 | if(qss_path == nullptr) 9 | return; 10 | QFile qss(qss_path); 11 | if(!qss.open(QFile::ReadOnly)) 12 | { 13 | qDebug()<<"Error: void setStyleQss()"; 14 | return; 15 | } 16 | qApp->setStyleSheet(qss.readAll()); 17 | qss.close(); 18 | } 19 | 20 | 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | QApplication a(argc, argv); 25 | // setStyleQss(":/keyboard.qss"); 26 | auto keyboard = VirtualKeyBoard::getKeyboard();//大小不可改变,使用 setFixeSize 27 | keyboard->init("/opt/UIfile/ChinesePY.db"); 28 | keyboard->setGeometry(600,100, 400,400); 29 | keyboard->show(); 30 | 31 | 32 | auto le = new QLineEdit(nullptr); 33 | le->setGeometry(600,600,200,40); 34 | le->show(); 35 | 36 | 37 | le = new QLineEdit(nullptr); 38 | le->setGeometry(0,700,200,40); 39 | le->show(); 40 | 41 | return a.exec(); 42 | } 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | //最多显示6个待选汉字 10 | #define MAX_VISIBLE (6) 11 | 12 | VirtualKeyBoard::VirtualKeyBoard(QWidget *parent) : 13 | QWidget(parent), 14 | ui(new Ui::Widget) 15 | { 16 | ui->setupUi(this); 17 | db_ = new QSqlDatabase; 18 | //添加数据库驱动 19 | if(QSqlDatabase::contains("my_sqlite")) 20 | *db_ = QSqlDatabase::database("my_sqlite"); 21 | else 22 | *db_ = QSqlDatabase::addDatabase("QSQLITE", "my_sqlite"); 23 | 24 | //设置数据库名称/指定数据库 25 | db_->setDatabaseName("ChinesePY.db");//:memory: 26 | //打开数据库 27 | if(!db_->open()) 28 | { 29 | qDebug()<lastError(); 30 | exit(-1); 31 | } 32 | } 33 | 34 | QStringList VirtualKeyBoard::getChineseList() 35 | { 36 | return chinese_list_; 37 | } 38 | 39 | VirtualKeyBoard::~VirtualKeyBoard() 40 | { 41 | delete ui; 42 | delete db_; 43 | } 44 | 45 | void VirtualKeyBoard::showChinese(const QString &key) 46 | { 47 | 48 | 49 | } 50 | 51 | void VirtualKeyBoard::on_lineEdit_textChanged(const QString &arg1) 52 | { 53 | chinese_list_.clear(); 54 | if(arg1.isEmpty()) 55 | return; 56 | if(QSqlDatabase::contains("my_sqlite")) 57 | *db_ = QSqlDatabase::database("my_sqlite"); 58 | else 59 | *db_ = QSqlDatabase::addDatabase("QSQLITE", "my_sqlite"); 60 | //打开数据库 61 | if(!db_->open()) 62 | { 63 | qDebug()<lastError(); 64 | return; 65 | } 66 | 67 | QString py(arg1); 68 | QSqlQuery query(*db_); 69 | int count(0); 70 | while(1)//根据拼音获取对因汉字/词组 71 | { 72 | const QString command = "select PinYin, Chinese from WordAndGroup where PinYin like ""'"+py+"%;'"; 73 | if(!query.exec(command)) 74 | { 75 | qDebug()<lastError(); 76 | goto error; 77 | } 78 | while(query.next()) 79 | { 80 | chinese_list_.append(query.value(1).toString()); 81 | } 82 | qDebug()<0) 84 | { 85 | is_last_ok_=true; 86 | last_py_=py+"%,"; 87 | break; 88 | }else 89 | { 90 | QString str = last_py_; 91 | str.remove(QRegExp("%,")); 92 | if(++count==1)//当查询不匹配时,将新加入的词汇当作新词的开头(eg1:guoj--> guo%,j eg2:guoji -->guo%,j%,i) 93 | { 94 | py=last_py_+arg1.mid(str.size()); 95 | } 96 | else if(count==2)//若之前可以匹配现在不行,则将新加入的字母当作新词的一部分拼音(eg1:guoj-->guo%,j eg2:guoji -->guo%ji) 97 | { 98 | QString str2 = last_py_; 99 | str2.remove(str2.lastIndexOf("%,"), 2); 100 | py=str2+arg1.mid(str.size()); 101 | 102 | }else if(count==3)//将"last_py_"最后3个字符替换成"%,",并补充当前拼音"arg1"尚未补充在"py"上的内容 103 | { //(处理退格键,词组时的鼻音问题(mingu-->min%gu)) 104 | if(arg1.size()close(); 121 | last_py_text_=arg1; 122 | return; 123 | } 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | class QSqlDatabase; 7 | 8 | namespace Ui { 9 | class Widget; 10 | } 11 | 12 | class VirtualKeyBoard : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit VirtualKeyBoard(QWidget *parent = nullptr); 18 | QStringList getChineseList(); 19 | ~VirtualKeyBoard(); 20 | 21 | void showChinese(const QString &key); 22 | 23 | private slots: 24 | void on_lineEdit_textChanged(const QString &arg1); 25 | 26 | private: 27 | Ui::Widget *ui; 28 | QSqlDatabase* db_; 29 | QStringList chinese_list_; 30 | QString last_py_; 31 | QString last_py_text_; 32 | bool is_last_ok_; 33 | }; 34 | 35 | #endif // MAINWINDOW_H 36 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 582 10 | 398 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 90 21 | 130 22 | 251 23 | 51 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 0 32 | 0 33 | 582 34 | 22 35 | 36 | 37 | 38 | 39 | 40 | TopToolBarArea 41 | 42 | 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/myqbtn.cpp: -------------------------------------------------------------------------------- 1 | #include "myqbtn.h" 2 | #include 3 | #include "myqproxystyle.h" 4 | //#include 5 | #include //控制连续点击按钮的效果 6 | 7 | 8 | MyqBtn::MyqBtn(QWidget *parent) : QPushButton(parent) 9 | { 10 | timer_ = new QTimer(this); 11 | connect(timer_, SIGNAL(timeout()), this, SLOT(updatePressStatus())); 12 | 13 | is_press_on_timer_ = new QTimer(this); 14 | connect(is_press_on_timer_, SIGNAL(timeout()), this, SLOT(pressOnSlot())); 15 | 16 | this->setStyle(new MyQProxyStyle); 17 | this->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); 18 | } 19 | 20 | void MyqBtn::setText(const QString &text) 21 | { 22 | QPushButton::setText(text); 23 | 24 | this->style()->unpolish(this); 25 | this->style()->polish(this); 26 | this->update(); 27 | } 28 | 29 | void MyqBtn::mousePressEvent(QMouseEvent *event) 30 | { 31 | is_press_on_timer_->start(100); 32 | return QPushButton::mousePressEvent(event); 33 | } 34 | 35 | 36 | void MyqBtn::mouseReleaseEvent(QMouseEvent *event) 37 | { 38 | is_press_on_=false; 39 | if(is_press_on_timer_->isActive()) 40 | is_press_on_timer_->stop(); 41 | 42 | pos2_ = event->pos(); 43 | if(this->rect().contains(pos2_)) 44 | { 45 | if(is_ok_) 46 | { 47 | is_ok_ = false; 48 | timer_->start(100);//限制连续点击速度 49 | emit clicked(this->text()); 50 | } 51 | } 52 | QPushButton::mouseReleaseEvent(event); 53 | } 54 | 55 | 56 | void MyqBtn::updatePressStatus() 57 | { 58 | is_ok_ = true; 59 | timer_->stop(); 60 | } 61 | 62 | void MyqBtn::pressOnSlot() 63 | { 64 | if(is_press_on_)emit clicked(this->text());//模拟连续点击 65 | is_press_on_=true; 66 | } 67 | 68 | 69 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/myqbtn.h: -------------------------------------------------------------------------------- 1 | #ifndef MYQBTN_H 2 | #define MYQBTN_H 3 | 4 | #include 5 | // 解决段时间连续点击按钮 6 | // 对按钮的不同操作 7 | // 8 | class QLabel; 9 | class MyqBtn : public QPushButton 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit MyqBtn(QWidget *parent = nullptr); 14 | 15 | void setText(const QString &text); 16 | 17 | protected: 18 | void mousePressEvent ( QMouseEvent * event ); 19 | void mouseReleaseEvent ( QMouseEvent * event ); 20 | 21 | private: 22 | QPoint pos2_; 23 | QTimer* timer_=nullptr; 24 | QTimer* is_press_on_timer_=nullptr; 25 | bool is_ok_=true; 26 | bool is_press_on_=false; 27 | // bool text_is_empty_=true; 28 | signals: 29 | void clicked(const QString&); 30 | // void mouse_command(int flag); 31 | // void mouse_ok_release(/*int unused = default_ret*/);//在按钮内释放 32 | private slots: 33 | void updatePressStatus(); 34 | void pressOnSlot(); 35 | 36 | public slots: 37 | 38 | 39 | }; 40 | 41 | #endif // MYQBTN_H 42 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/myqlb.cpp: -------------------------------------------------------------------------------- 1 | #include "myqlb.h" 2 | #include 3 | MyqLb::MyqLb(QWidget *parent) : QLabel(parent) 4 | { 5 | 6 | } 7 | 8 | void MyqLb::setText(const QString &text) 9 | { 10 | QLabel::setText(text); 11 | 12 | this->style()->unpolish(this); 13 | this->style()->polish(this); 14 | this->update(); 15 | } 16 | 17 | void MyqLb::clear() 18 | { 19 | QLabel::setText(""); 20 | this->style()->unpolish(this); 21 | this->style()->polish(this); 22 | this->update(); 23 | } 24 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/myqlb.h: -------------------------------------------------------------------------------- 1 | #ifndef MYQLB_H 2 | #define MYQLB_H 3 | 4 | #include 5 | class MyqLb : public QLabel 6 | { 7 | Q_OBJECT 8 | public: 9 | explicit MyqLb(QWidget *parent = nullptr); 10 | void setText(const QString &text); 11 | signals: 12 | 13 | public slots: 14 | 15 | void clear(); 16 | 17 | }; 18 | 19 | #endif // MYQLB_H 20 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/myqproxystyle.cpp: -------------------------------------------------------------------------------- 1 | #include "myqproxystyle.h" 2 | 3 | #include 4 | 5 | void MyQProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const 6 | { 7 | if (PE_FrameFocusRect == element)//当焦点集中时的策略 8 | { 9 | //这里不做任何操作,Qt默认是绘制矩形虚线框,以及焦点时的content背景色 10 | } 11 | else 12 | { 13 | QProxyStyle::drawPrimitive(element, option,painter, widget); 14 | } 15 | } 16 | 17 | int MyQProxyStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const 18 | { 19 | if (metric == QStyle::PM_TextCursorWidth)//lineEdit光标不绘制 20 | return 0; 21 | return QProxyStyle::pixelMetric(metric, option, widget); 22 | } 23 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/myqproxystyle.h: -------------------------------------------------------------------------------- 1 | #ifndef MYQPROXYSTYLE_H 2 | #define MYQPROXYSTYLE_H 3 | 4 | #include 5 | #include 6 | class PrimitiveElement; 7 | class QStyleOption; 8 | 9 | //用于解决各种样式问题 10 | 11 | class MyQProxyStyle : public QProxyStyle 12 | { 13 | Q_OBJECT 14 | public: 15 | 16 | virtual void drawPrimitive(PrimitiveElement element, const QStyleOption * option, 17 | QPainter * painter, const QWidget * widget = nullptr) const; 18 | virtual int pixelMetric(PixelMetric metric, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const; 19 | 20 | 21 | signals: 22 | 23 | public slots: 24 | }; 25 | 26 | #endif // MYQPROXYSTYLE_H 27 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/readme.txt: -------------------------------------------------------------------------------- 1 | 用于 键盘选择了哪个 le 的样式变化 2 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/virtualKeyBoard.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-01-28T15:51:44 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | QT +=sql 10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 11 | 12 | #TARGET = useMyChinesePinYinDB 13 | TARGET = /home/share/nfs/bin/mykeyboard 14 | TEMPLATE = app 15 | #include(sqlite3/sqlite3.pri) 16 | 17 | # The following define makes your compiler emit warnings if you use 18 | # any feature of Qt which has been marked as deprecated (the exact warnings 19 | # depend on your compiler). Please consult the documentation of the 20 | # deprecated API in order to know how to port your code away from it. 21 | DEFINES += QT_DEPRECATED_WARNINGS 22 | 23 | # You can also make your code fail to compile if you use deprecated APIs. 24 | # In order to do so, uncomment the following line. 25 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 26 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 27 | 28 | CONFIG += c++11 29 | 30 | 31 | SOURCES += \ 32 | main.cpp \ 33 | virtualkeyboard.cpp 34 | 35 | HEADERS += \ 36 | virtualkeyboard.h 37 | 38 | FORMS += \ 39 | virtualkeyboard.ui 40 | 41 | # Default rules for deployment. 42 | qnx: target.path = /tmp/$${TARGET}/bin 43 | else: unix:!android: target.path = /opt/$${TARGET}/bin 44 | !isEmpty(target.path): INSTALLS += target 45 | 46 | RESOURCES += \ 47 | Resource/VirtualKeyBoardResource.qrc 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/virtualkeyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef VIRTUALKEYBOARD_H 2 | #define VIRTUALKEYBOARD_H 3 | /* 4 | 使用说明: 使用Qwidget实现QT键盘,已经实现的功能:中英文切换、中文词组支持、中英文基础符号、自动弹出虚拟键盘 5 | 本工程下有一个Resources文件夹,下面有一个已经制作好的汉字数据库,需要将其放到可执行文件目录下才可正常使用汉字功能 6 | 所有样式功能均在资源文件中的QSS中实现 7 | 8 | 如何实现中文词组:使用数据库的模糊搜索方式,实现中文词组,并自己制作汉字数据库。 9 | 10 | 作者:seejv 11 | 最后修改时间:2020-06-30 12 | 本次更新,删除了自定义的 label qpushbutton, 同时解决了在输入过程中光标不可见的问题。并使用一些比较方便的函数: 13 | connect(qApp, &QApplication::focusChanged, this, &VirtualKeyBoard::focusChangedSlot);//来完成键盘响应 14 | QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier, QString()); //完成文本删除 15 | QKeyEvent keyPress(QEvent::KeyPress, 0, Qt::NoModifier, QString(str));//完成文本内容的插入 16 | 17 | 比较重要的几个函数: 18 | getChineseListMap //获取汉字词组 19 | focusChangedSlot //自动弹出键盘 20 | InsertTextToCurFocusWt //向控件插入文本 21 | DeleteTextFromCurFocusWt //向控件删除一个字符 22 | */ 23 | #include 24 | #include 25 | 26 | class QPushButton; 27 | class QSqlDatabase; 28 | class QLineEdit; 29 | class QLabel; 30 | //class MyVirtualKeyBoard_qBtn; 31 | namespace Ui { 32 | class VirtualKeyBoard; 33 | } 34 | 35 | 36 | class VirtualKeyBoard : public QWidget 37 | { 38 | Q_OBJECT 39 | public: 40 | static VirtualKeyBoard *getKeyboard(); 41 | void init(const QString& db_path); //"" 表示不使用 汉字词组 42 | 43 | ~VirtualKeyBoard()override; 44 | 45 | //使用说明,要求输入控件必须是自定义的 46 | //setTextSlot(QString) 用于更新输入控件内容 47 | //curTextSignal(QString) 用于获取当前文本控件的内容 48 | // void setAutoShow(QObject* input_widget);//eg. setAutoShow(new myLineEdit(this));//控件必须是自定义的 49 | 50 | 51 | protected: 52 | void showEvent(QShowEvent *event)override; 53 | void hideEvent(QHideEvent *event)override; 54 | 55 | 56 | private: 57 | Ui::VirtualKeyBoard *ui; 58 | explicit VirtualKeyBoard(QWidget *parent = nullptr); 59 | static VirtualKeyBoard* g_keyboard; 60 | QLabel* lb_display_text_=nullptr; 61 | 62 | 63 | private: 64 | QWidget* cur_focus_wt_ = nullptr; //记录当前焦点控件 65 | 66 | 67 | void init1();//添加UI中的变量及信号与槽 68 | void init2(const QString& db_path);//布局、数据、等只需要初始化一次的 69 | 70 | QMap getChineseListMap(const QString &cur_text);//获取汉字列表,重要----------------------------------------- 71 | void clearBuffer();//清除拼音、等缓存 72 | void switchLetterStatus();//切换大小写 73 | QSqlDatabase* db_=nullptr; 74 | int cur_py_page_=-1; 75 | QString last_py_{};//上一次保存的可寻找到汉字的拼音组合 76 | QString cur_py_text_{}; 77 | QString last_py_text_{};//用于确定退格按钮 78 | // QLineEdit* out_side_le_=nullptr; 79 | // QString cur_out_side_text_=""; 80 | //用于每行的按钮 81 | enum{row_1, row_2, row_3, row_4, row_5}; 82 | QMap> btn_list_map_; 83 | 84 | enum{en0,en1,en2,ch0,ch1,ch2};//不同模式下按钮的显示文本,0代表没切换符号时的样子,1,2,3代表不同符号页面, 85 | //需要增加新符号则道init2()中去添加, 86 | int symbal_page_=en0; 87 | QMapsymbol_list_map_={}; 88 | void setSymbolPage(int enNum_chNum);//切换不同符号页 89 | 90 | enum{is_ch_mode,is_capital_mode}; 91 | QMapmode_flag_map_{}; 92 | 93 | 94 | // typedef void (*setText_fp) (const QString&); 95 | QString objName_=""; 96 | // QMapobjName_fp_map_; 97 | 98 | void ShowPinYinTip();//显示当前输入的拼音 99 | void InsertTextToCurFocusWt(const QString& str); 100 | void DeleteTextFromCurFocusWt(); 101 | void recKeyClicked(const QString& str);//处理所有虚拟键盘的按钮 ------------------------------------------------- 102 | private slots: 103 | void showChinese(const QString &key, const QMap &chinese_list_map); 104 | void recKeyClickedSlot();//处理所有虚拟键盘的按钮 ------------------------------------------------- 105 | void selectChinese(); 106 | void focusChangedSlot(QWidget *old, QWidget *now);//处理 qApp 过来的内容 107 | 108 | 109 | // void show(const QString &curText, const QString &recObjName); 110 | // void show(const QString &curText, const QString &recObjName, setText_fp); 111 | 112 | public slots: 113 | void show(); 114 | void hide(); 115 | signals: 116 | void changedOutSideTextSignal(const QString &text, const QString &objName);//表示当前外部输入源文本已经被改变 117 | void setDefaultColorSignal(); 118 | }; 119 | 120 | #endif // VIRTUALKEYBOARD_H 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /QtVirtualKeyboard/useKeyBoard_Demo/virtualkeyboard_hasQSQLITE/virtualkeyboard.pri: -------------------------------------------------------------------------------- 1 | QMAKE_CXXFLAGS += -std=c++0x 2 | QT +=sql 3 | QT += core gui 4 | CONFIG += c++11 5 | 6 | INCLUDEPATH += $$PWD/ #头文件路径 7 | DEPENDPATH += $$PWD/ #编译时依赖的相关路径 8 | 9 | HEADERS += $$PWD/virtualkeyboard.h 10 | 11 | 12 | SOURCES += $$PWD/virtualkeyboard.cpp 13 | 14 | FORMS += $$PWD/virtualkeyboard.ui 15 | 16 | RESOURCES += $$PWD/Resource/VirtualKeyBoardResource.qrc 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QtProject 2 | 项目地址来自 github: https://github.com/seejv/QtProject 3 | 4 | 自定义 qt 控件 5 | 工程: 6 | 1. QtVirtualKeyboard: 7 | 一个使用 QWiget 开发的 QT 虚拟键盘,理论上可以适用所有的 qt 版本,本项目使用数据库 sqlite3 来实现拼音词组。 解决需求:嵌入式或者其他场景需要用到 qt 键盘来完成汉字词组的输入,并且无法使用 qml。 8 | ![qt虚拟键盘演示](https://github.com/seejv/QtProject/blob/master/QtVirtualKeyboard/useKeyBoard_Demo/keyboard_show-how.gif) 9 | 10 | 2. QtRotatingInArmForQt5: 11 | 添加 qt5 旋转补丁包,以及修复会导致透明失效的问题。(环境 qt5.5.1),可能由于补丁包是 qt5.4,所以才会导致打了补丁包后无法正常设置透明效果。 12 | 具体需要哪些内容请自行决定。 13 | 14 | 3. QtPagingToolBar: 15 | 一个使用 QWidget 开发的分页栏,类似于网页分页栏的效果。 16 | ![qt分页栏演示](https://github.com/seejv/QtProject/blob/master/QtPagingToolBar/pagingtoolbar_show.gif) 17 | 18 | 4. QtSliptBotton: 19 | 一个使用 QWidget 开发的单选滑块按钮。 20 | ![qt滑动按钮演示](https://github.com/seejv/QtProject/blob/master/QtSliptBotton/slipt_btn.png) 21 | 22 | 5. QtDrawingBoard: 23 | 一个 Qt 画板,支持擦除、恢复,保存,可以用于嵌入式 24 | ![qt画板演示](https://github.com/seejv/QtProject/blob/master/QtDrawingBoard/drawingboard.gif) 25 | 26 | 6. QtTimer: 27 | 定时器, linux 不用再找定时器了 28 | ![qt定时器演示](https://github.com/seejv/QtProject/blob/master/QtTimer/mytimer.gif) 29 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/platformsupport/fbconvenience/qfbscreen.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #include "qfbscreen_p.h" 35 | #include "qfbcursor_p.h" 36 | #include "qfbwindow_p.h" 37 | #include "qfbbackingstore_p.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | 46 | QT_BEGIN_NAMESPACE 47 | 48 | QFbScreen::QFbScreen() : mUpdatePending(false), mCursor(0), mGeometry(), mDepth(16), mFormat(QImage::Format_RGB16), mScreenImage(0), mCompositePainter(0), mIsUpToDate(false) 49 | { 50 | } 51 | 52 | QFbScreen::~QFbScreen() 53 | { 54 | delete mCompositePainter; 55 | delete mScreenImage; 56 | } 57 | 58 | void QFbScreen::initializeCompositor() 59 | { 60 | mScreenImage = new QImage(mGeometry.size(), mFormat); 61 | scheduleUpdate(); 62 | } 63 | 64 | bool QFbScreen::event(QEvent *event) 65 | { 66 | if (event->type() == QEvent::UpdateRequest) { 67 | doRedraw(); 68 | mUpdatePending = false; 69 | return true; 70 | } 71 | return QObject::event(event); 72 | } 73 | 74 | void QFbScreen::addWindow(QFbWindow *window) 75 | { 76 | mWindowStack.prepend(window); 77 | if (!mPendingBackingStores.isEmpty()) { 78 | //check if we have a backing store for this window 79 | for (int i = 0; i < mPendingBackingStores.size(); ++i) { 80 | QFbBackingStore *bs = mPendingBackingStores.at(i); 81 | // this gets called during QWindow::create() at a point where the 82 | // invariant (window->handle()->window() == window) is broken 83 | if (bs->window() == window->window()) { 84 | window->setBackingStore(bs); 85 | mPendingBackingStores.removeAt(i); 86 | break; 87 | } 88 | } 89 | } 90 | invalidateRectCache(); 91 | setDirty(window->geometry()); 92 | QWindow *w = topWindow(); 93 | QWindowSystemInterface::handleWindowActivated(w); 94 | topWindowChanged(w); 95 | } 96 | 97 | void QFbScreen::removeWindow(QFbWindow *window) 98 | { 99 | mWindowStack.removeOne(window); 100 | invalidateRectCache(); 101 | setDirty(window->geometry()); 102 | QWindow *w = topWindow(); 103 | QWindowSystemInterface::handleWindowActivated(w); 104 | topWindowChanged(w); 105 | } 106 | 107 | void QFbScreen::raise(QFbWindow *window) 108 | { 109 | int index = mWindowStack.indexOf(window); 110 | if (index <= 0) 111 | return; 112 | mWindowStack.move(index, 0); 113 | invalidateRectCache(); 114 | setDirty(window->geometry()); 115 | QWindow *w = topWindow(); 116 | QWindowSystemInterface::handleWindowActivated(w); 117 | topWindowChanged(w); 118 | } 119 | 120 | void QFbScreen::lower(QFbWindow *window) 121 | { 122 | int index = mWindowStack.indexOf(window); 123 | if (index == -1 || index == (mWindowStack.size() - 1)) 124 | return; 125 | mWindowStack.move(index, mWindowStack.size() - 1); 126 | invalidateRectCache(); 127 | setDirty(window->geometry()); 128 | QWindow *w = topWindow(); 129 | QWindowSystemInterface::handleWindowActivated(w); 130 | topWindowChanged(w); 131 | } 132 | 133 | QWindow *QFbScreen::topWindow() const 134 | { 135 | foreach (QFbWindow *fbw, mWindowStack) 136 | if (fbw->window()->type() == Qt::Window || fbw->window()->type() == Qt::Dialog) 137 | return fbw->window(); 138 | return 0; 139 | } 140 | 141 | QWindow *QFbScreen::topLevelAt(const QPoint & p) const 142 | { 143 | foreach (QFbWindow *fbw, mWindowStack) { 144 | if (fbw->geometry().contains(p, false) && fbw->window()->isVisible()) 145 | return fbw->window(); 146 | } 147 | return 0; 148 | } 149 | 150 | void QFbScreen::setDirty(const QRect &rect) 151 | { 152 | QRect intersection = rect.intersected(mGeometry); 153 | QPoint screenOffset = mGeometry.topLeft(); 154 | mRepaintRegion += intersection.translated(-screenOffset); // global to local translation 155 | scheduleUpdate(); 156 | } 157 | 158 | void QFbScreen::scheduleUpdate() 159 | { 160 | if (!mUpdatePending) { 161 | mUpdatePending = true; 162 | QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); 163 | } 164 | } 165 | 166 | void QFbScreen::setPhysicalSize(const QSize &size) 167 | { 168 | mPhysicalSize = size; 169 | } 170 | 171 | void QFbScreen::setGeometry(const QRect &rect) 172 | { 173 | delete mCompositePainter; 174 | mCompositePainter = 0; 175 | delete mScreenImage; 176 | mGeometry = rect; 177 | mScreenImage = new QImage(mGeometry.size(), mFormat); 178 | invalidateRectCache(); 179 | QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry(), availableGeometry()); 180 | resizeMaximizedWindows(); 181 | } 182 | 183 | void QFbScreen::generateRects() 184 | { 185 | mCachedRects.clear(); 186 | QPoint screenOffset = mGeometry.topLeft(); 187 | QRegion remainingScreen(mGeometry.translated(-screenOffset)); // global to local translation 188 | 189 | for (int i = 0; i < mWindowStack.length(); i++) { 190 | if (remainingScreen.isEmpty()) 191 | break; 192 | #if 0 193 | if (!mWindowStack[i]->isVisible()) 194 | continue; 195 | if (mWindowStack[i]->isMinimized()) 196 | continue; 197 | 198 | if (!mWindowStack[i]->testAttribute(Qt::WA_TranslucentBackground)) { 199 | QRect localGeometry = mWindowStack.at(i)->geometry().translated(-screenOffset); // global to local translation 200 | remainingScreen -= localGeometry; 201 | QRegion windowRegion(localGeometry); 202 | windowRegion -= remainingScreen; 203 | foreach (const QRect &rect, windowRegion.rects()) { 204 | mCachedRects += QPair(rect, i); 205 | } 206 | } 207 | #endif 208 | } 209 | foreach (const QRect &rect, remainingScreen.rects()) 210 | mCachedRects += QPair(rect, -1); 211 | mIsUpToDate = true; 212 | return; 213 | } 214 | 215 | QRegion QFbScreen::doRedraw() 216 | { 217 | QPoint screenOffset = mGeometry.topLeft(); 218 | 219 | QRegion touchedRegion; 220 | if (mCursor && mCursor->isDirty() && mCursor->isOnScreen()) { 221 | QRect lastCursor = mCursor->dirtyRect(); 222 | mRepaintRegion += lastCursor; 223 | } 224 | if (mRepaintRegion.isEmpty() && (!mCursor || !mCursor->isDirty())) { 225 | return touchedRegion; 226 | } 227 | 228 | QVector rects = mRepaintRegion.rects(); 229 | 230 | if (!mIsUpToDate) 231 | generateRects(); 232 | 233 | if (!mCompositePainter) 234 | mCompositePainter = new QPainter(mScreenImage); 235 | for (int rectIndex = 0; rectIndex < mRepaintRegion.rectCount(); rectIndex++) { 236 | QRegion rectRegion = rects[rectIndex]; 237 | 238 | for (int i = 0; i < mCachedRects.length(); i++) { 239 | QRect screenSubRect = mCachedRects[i].first; 240 | int layer = mCachedRects[i].second; 241 | QRegion intersect = rectRegion.intersected(screenSubRect); 242 | 243 | if (intersect.isEmpty()) 244 | continue; 245 | 246 | rectRegion -= intersect; 247 | 248 | // we only expect one rectangle, but defensive coding... 249 | foreach (const QRect &rect, intersect.rects()) { 250 | bool firstLayer = true; 251 | if (layer == -1) { 252 | //mCompositePainter->fillRect(rect, Qt::green); 253 | //edit by zc 254 | mCompositePainter->setCompositionMode(QPainter::CompositionMode_Clear); 255 | mCompositePainter->fillRect(rect, Qt::transparent); 256 | //mCompositePainter->fillRect(rect, Qt::green); 257 | mCompositePainter->setCompositionMode(QPainter::CompositionMode_SourceOver); 258 | firstLayer = false; 259 | layer = mWindowStack.size() - 1; 260 | } 261 | 262 | for (int layerIndex = layer; layerIndex != -1; layerIndex--) { 263 | if (!mWindowStack[layerIndex]->window()->isVisible()) 264 | continue; 265 | // if (mWindowStack[layerIndex]->isMinimized()) 266 | // continue; 267 | 268 | QRect windowRect = mWindowStack[layerIndex]->geometry().translated(-screenOffset); 269 | QRect windowIntersect = rect.translated(-windowRect.left(), 270 | -windowRect.top()); 271 | 272 | 273 | QFbBackingStore *backingStore = mWindowStack[layerIndex]->backingStore(); 274 | 275 | if (backingStore) { 276 | backingStore->lock(); 277 | mCompositePainter->drawImage(rect, backingStore->image(), windowIntersect); 278 | backingStore->unlock(); 279 | } 280 | if (firstLayer) { 281 | firstLayer = false; 282 | } 283 | } 284 | } 285 | } 286 | } 287 | 288 | QRect cursorRect; 289 | if (mCursor && (mCursor->isDirty() || mRepaintRegion.intersects(mCursor->lastPainted()))) { 290 | cursorRect = mCursor->drawCursor(*mCompositePainter); 291 | touchedRegion += cursorRect; 292 | } 293 | touchedRegion += mRepaintRegion; 294 | mRepaintRegion = QRegion(); 295 | 296 | 297 | 298 | // qDebug() << "QFbScreen::doRedraw" << mWindowStack.size() << mScreenImage->size() << touchedRegion; 299 | 300 | return touchedRegion; 301 | } 302 | 303 | QFbWindow *QFbScreen::windowForId(WId wid) const 304 | { 305 | for (int i = 0; i < mWindowStack.count(); ++i) 306 | if (mWindowStack[i]->winId() == wid) 307 | return mWindowStack[i]; 308 | 309 | return 0; 310 | } 311 | 312 | QT_END_NAMESPACE 313 | 314 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/platformsupport/fbconvenience/qfbscreen.cpp.bak: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #include "qfbscreen_p.h" 35 | #include "qfbcursor_p.h" 36 | #include "qfbwindow_p.h" 37 | #include "qfbbackingstore_p.h" 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | 46 | QT_BEGIN_NAMESPACE 47 | 48 | QFbScreen::QFbScreen() : mUpdatePending(false), mCursor(0), mGeometry(), mDepth(16), mFormat(QImage::Format_RGB16), mScreenImage(0), mCompositePainter(0), mIsUpToDate(false) 49 | { 50 | } 51 | 52 | QFbScreen::~QFbScreen() 53 | { 54 | delete mCompositePainter; 55 | delete mScreenImage; 56 | } 57 | 58 | void QFbScreen::initializeCompositor() 59 | { 60 | mScreenImage = new QImage(mGeometry.size(), mFormat); 61 | scheduleUpdate(); 62 | } 63 | 64 | bool QFbScreen::event(QEvent *event) 65 | { 66 | if (event->type() == QEvent::UpdateRequest) { 67 | doRedraw(); 68 | mUpdatePending = false; 69 | return true; 70 | } 71 | return QObject::event(event); 72 | } 73 | 74 | void QFbScreen::addWindow(QFbWindow *window) 75 | { 76 | mWindowStack.prepend(window); 77 | if (!mPendingBackingStores.isEmpty()) { 78 | //check if we have a backing store for this window 79 | for (int i = 0; i < mPendingBackingStores.size(); ++i) { 80 | QFbBackingStore *bs = mPendingBackingStores.at(i); 81 | // this gets called during QWindow::create() at a point where the 82 | // invariant (window->handle()->window() == window) is broken 83 | if (bs->window() == window->window()) { 84 | window->setBackingStore(bs); 85 | mPendingBackingStores.removeAt(i); 86 | break; 87 | } 88 | } 89 | } 90 | invalidateRectCache(); 91 | setDirty(window->geometry()); 92 | QWindow *w = topWindow(); 93 | QWindowSystemInterface::handleWindowActivated(w); 94 | topWindowChanged(w); 95 | } 96 | 97 | void QFbScreen::removeWindow(QFbWindow *window) 98 | { 99 | mWindowStack.removeOne(window); 100 | invalidateRectCache(); 101 | setDirty(window->geometry()); 102 | QWindow *w = topWindow(); 103 | QWindowSystemInterface::handleWindowActivated(w); 104 | topWindowChanged(w); 105 | } 106 | 107 | void QFbScreen::raise(QFbWindow *window) 108 | { 109 | int index = mWindowStack.indexOf(window); 110 | if (index <= 0) 111 | return; 112 | mWindowStack.move(index, 0); 113 | invalidateRectCache(); 114 | setDirty(window->geometry()); 115 | QWindow *w = topWindow(); 116 | QWindowSystemInterface::handleWindowActivated(w); 117 | topWindowChanged(w); 118 | } 119 | 120 | void QFbScreen::lower(QFbWindow *window) 121 | { 122 | int index = mWindowStack.indexOf(window); 123 | if (index == -1 || index == (mWindowStack.size() - 1)) 124 | return; 125 | mWindowStack.move(index, mWindowStack.size() - 1); 126 | invalidateRectCache(); 127 | setDirty(window->geometry()); 128 | QWindow *w = topWindow(); 129 | QWindowSystemInterface::handleWindowActivated(w); 130 | topWindowChanged(w); 131 | } 132 | 133 | QWindow *QFbScreen::topWindow() const 134 | { 135 | foreach (QFbWindow *fbw, mWindowStack) 136 | if (fbw->window()->type() == Qt::Window || fbw->window()->type() == Qt::Dialog) 137 | return fbw->window(); 138 | return 0; 139 | } 140 | 141 | QWindow *QFbScreen::topLevelAt(const QPoint & p) const 142 | { 143 | foreach (QFbWindow *fbw, mWindowStack) { 144 | if (fbw->geometry().contains(p, false) && fbw->window()->isVisible()) 145 | return fbw->window(); 146 | } 147 | return 0; 148 | } 149 | 150 | void QFbScreen::setDirty(const QRect &rect) 151 | { 152 | QRect intersection = rect.intersected(mGeometry); 153 | QPoint screenOffset = mGeometry.topLeft(); 154 | mRepaintRegion += intersection.translated(-screenOffset); // global to local translation 155 | scheduleUpdate(); 156 | } 157 | 158 | void QFbScreen::scheduleUpdate() 159 | { 160 | if (!mUpdatePending) { 161 | mUpdatePending = true; 162 | QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); 163 | } 164 | } 165 | 166 | void QFbScreen::setPhysicalSize(const QSize &size) 167 | { 168 | mPhysicalSize = size; 169 | } 170 | 171 | void QFbScreen::setGeometry(const QRect &rect) 172 | { 173 | delete mCompositePainter; 174 | mCompositePainter = 0; 175 | delete mScreenImage; 176 | mGeometry = rect; 177 | mScreenImage = new QImage(mGeometry.size(), mFormat); 178 | invalidateRectCache(); 179 | QWindowSystemInterface::handleScreenGeometryChange(QPlatformScreen::screen(), geometry(), availableGeometry()); 180 | resizeMaximizedWindows(); 181 | } 182 | 183 | void QFbScreen::generateRects() 184 | { 185 | mCachedRects.clear(); 186 | QPoint screenOffset = mGeometry.topLeft(); 187 | QRegion remainingScreen(mGeometry.translated(-screenOffset)); // global to local translation 188 | 189 | for (int i = 0; i < mWindowStack.length(); i++) { 190 | if (remainingScreen.isEmpty()) 191 | break; 192 | #if 0 193 | if (!mWindowStack[i]->isVisible()) 194 | continue; 195 | if (mWindowStack[i]->isMinimized()) 196 | continue; 197 | 198 | if (!mWindowStack[i]->testAttribute(Qt::WA_TranslucentBackground)) { 199 | QRect localGeometry = mWindowStack.at(i)->geometry().translated(-screenOffset); // global to local translation 200 | remainingScreen -= localGeometry; 201 | QRegion windowRegion(localGeometry); 202 | windowRegion -= remainingScreen; 203 | foreach (const QRect &rect, windowRegion.rects()) { 204 | mCachedRects += QPair(rect, i); 205 | } 206 | } 207 | #endif 208 | } 209 | foreach (const QRect &rect, remainingScreen.rects()) 210 | mCachedRects += QPair(rect, -1); 211 | mIsUpToDate = true; 212 | return; 213 | } 214 | 215 | QRegion QFbScreen::doRedraw() 216 | { 217 | QPoint screenOffset = mGeometry.topLeft(); 218 | 219 | QRegion touchedRegion; 220 | if (mCursor && mCursor->isDirty() && mCursor->isOnScreen()) { 221 | QRect lastCursor = mCursor->dirtyRect(); 222 | mRepaintRegion += lastCursor; 223 | } 224 | if (mRepaintRegion.isEmpty() && (!mCursor || !mCursor->isDirty())) { 225 | return touchedRegion; 226 | } 227 | 228 | QVector rects = mRepaintRegion.rects(); 229 | 230 | if (!mIsUpToDate) 231 | generateRects(); 232 | 233 | if (!mCompositePainter) 234 | mCompositePainter = new QPainter(mScreenImage); 235 | for (int rectIndex = 0; rectIndex < mRepaintRegion.rectCount(); rectIndex++) { 236 | QRegion rectRegion = rects[rectIndex]; 237 | 238 | for (int i = 0; i < mCachedRects.length(); i++) { 239 | QRect screenSubRect = mCachedRects[i].first; 240 | int layer = mCachedRects[i].second; 241 | QRegion intersect = rectRegion.intersected(screenSubRect); 242 | 243 | if (intersect.isEmpty()) 244 | continue; 245 | 246 | rectRegion -= intersect; 247 | 248 | // we only expect one rectangle, but defensive coding... 249 | foreach (const QRect &rect, intersect.rects()) { 250 | bool firstLayer = true; 251 | if (layer == -1) { 252 | mCompositePainter->fillRect(rect, Qt::black); 253 | firstLayer = false; 254 | layer = mWindowStack.size() - 1; 255 | } 256 | 257 | for (int layerIndex = layer; layerIndex != -1; layerIndex--) { 258 | if (!mWindowStack[layerIndex]->window()->isVisible()) 259 | continue; 260 | // if (mWindowStack[layerIndex]->isMinimized()) 261 | // continue; 262 | 263 | QRect windowRect = mWindowStack[layerIndex]->geometry().translated(-screenOffset); 264 | QRect windowIntersect = rect.translated(-windowRect.left(), 265 | -windowRect.top()); 266 | 267 | 268 | QFbBackingStore *backingStore = mWindowStack[layerIndex]->backingStore(); 269 | 270 | if (backingStore) { 271 | backingStore->lock(); 272 | mCompositePainter->drawImage(rect, backingStore->image(), windowIntersect); 273 | backingStore->unlock(); 274 | } 275 | if (firstLayer) { 276 | firstLayer = false; 277 | } 278 | } 279 | } 280 | } 281 | } 282 | 283 | QRect cursorRect; 284 | if (mCursor && (mCursor->isDirty() || mRepaintRegion.intersects(mCursor->lastPainted()))) { 285 | cursorRect = mCursor->drawCursor(*mCompositePainter); 286 | touchedRegion += cursorRect; 287 | } 288 | touchedRegion += mRepaintRegion; 289 | mRepaintRegion = QRegion(); 290 | 291 | 292 | 293 | // qDebug() << "QFbScreen::doRedraw" << mWindowStack.size() << mScreenImage->size() << touchedRegion; 294 | 295 | return touchedRegion; 296 | } 297 | 298 | QFbWindow *QFbScreen::windowForId(WId wid) const 299 | { 300 | for (int i = 0; i < mWindowStack.count(); ++i) 301 | if (mWindowStack[i]->winId() == wid) 302 | return mWindowStack[i]; 303 | 304 | return 0; 305 | } 306 | 307 | QT_END_NAMESPACE 308 | 309 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #include "qlinuxfbscreen.h" 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include // overrides QT_OPEN 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | QT_BEGIN_NAMESPACE 60 | 61 | static int openFramebufferDevice(const QString &dev) 62 | { 63 | int fd = -1; 64 | 65 | if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0) 66 | fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR); 67 | 68 | if (fd == -1) { 69 | if (access(dev.toLatin1().constData(), R_OK) == 0) 70 | fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY); 71 | } 72 | 73 | return fd; 74 | } 75 | 76 | static int determineDepth(const fb_var_screeninfo &vinfo) 77 | { 78 | int depth = vinfo.bits_per_pixel; 79 | if (depth== 24) { 80 | depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; 81 | if (depth <= 0) 82 | depth = 24; // reset if color component lengths are not reported 83 | } else if (depth == 16) { 84 | depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; 85 | if (depth <= 0) 86 | depth = 16; 87 | } 88 | return depth; 89 | } 90 | 91 | static QRect determineGeometry(const fb_var_screeninfo &vinfo, const QRect &userGeometry) 92 | { 93 | int xoff = vinfo.xoffset; 94 | int yoff = vinfo.yoffset; 95 | int w, h; 96 | if (userGeometry.isValid()) { 97 | w = userGeometry.width(); 98 | h = userGeometry.height(); 99 | if ((uint)w > vinfo.xres) 100 | w = vinfo.xres; 101 | if ((uint)h > vinfo.yres) 102 | h = vinfo.yres; 103 | 104 | int xxoff = userGeometry.x(), yyoff = userGeometry.y(); 105 | if (xxoff != 0 || yyoff != 0) { 106 | if (xxoff < 0 || xxoff + w > (int)(vinfo.xres)) 107 | xxoff = vinfo.xres - w; 108 | if (yyoff < 0 || yyoff + h > (int)(vinfo.yres)) 109 | yyoff = vinfo.yres - h; 110 | xoff += xxoff; 111 | yoff += yyoff; 112 | } else { 113 | xoff += (vinfo.xres - w)/2; 114 | yoff += (vinfo.yres - h)/2; 115 | } 116 | } else { 117 | w = vinfo.xres; 118 | h = vinfo.yres; 119 | } 120 | 121 | if (w == 0 || h == 0) { 122 | qWarning("Unable to find screen geometry, using 320x240"); 123 | w = 320; 124 | h = 240; 125 | } 126 | 127 | return QRect(xoff, yoff, w, h); 128 | } 129 | 130 | static QSizeF determinePhysicalSize(const fb_var_screeninfo &vinfo, const QSize &mmSize, const QSize &res) 131 | { 132 | int mmWidth = mmSize.width(), mmHeight = mmSize.height(); 133 | 134 | if (mmWidth <= 0 && mmHeight <= 0) { 135 | if (vinfo.width != 0 && vinfo.height != 0 136 | && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) { 137 | mmWidth = vinfo.width; 138 | mmHeight = vinfo.height; 139 | } else { 140 | const int dpi = 100; 141 | mmWidth = qRound(res.width() * 25.4 / dpi); 142 | mmHeight = qRound(res.height() * 25.4 / dpi); 143 | } 144 | } else if (mmWidth > 0 && mmHeight <= 0) { 145 | mmHeight = res.height() * mmWidth/res.width(); 146 | } else if (mmHeight > 0 && mmWidth <= 0) { 147 | mmWidth = res.width() * mmHeight/res.height(); 148 | } 149 | 150 | return QSize(mmWidth, mmHeight); 151 | } 152 | 153 | static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth) 154 | { 155 | const fb_bitfield rgba[4] = { info.red, info.green, 156 | info.blue, info.transp }; 157 | 158 | QImage::Format format = QImage::Format_Invalid; 159 | 160 | switch (depth) { 161 | case 32: { 162 | const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0}, 163 | {0, 8, 0}, {24, 8, 0}}; 164 | const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0}, 165 | {16, 8, 0}, {24, 8, 0}}; 166 | if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) { 167 | format = QImage::Format_ARGB32; 168 | } else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) { 169 | format = QImage::Format_RGB32; 170 | } else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) { 171 | format = QImage::Format_RGB32; 172 | // pixeltype = BGRPixel; 173 | } 174 | break; 175 | } 176 | case 24: { 177 | const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0}, 178 | {0, 8, 0}, {0, 0, 0}}; 179 | const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0}, 180 | {16, 8, 0}, {0, 0, 0}}; 181 | if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) { 182 | format = QImage::Format_RGB888; 183 | } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) { 184 | format = QImage::Format_RGB888; 185 | // pixeltype = BGRPixel; 186 | } 187 | break; 188 | } 189 | case 18: { 190 | const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0}, 191 | {0, 6, 0}, {0, 0, 0}}; 192 | if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0) 193 | format = QImage::Format_RGB666; 194 | break; 195 | } 196 | case 16: { 197 | const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0}, 198 | {0, 5, 0}, {0, 0, 0}}; 199 | const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0}, 200 | {11, 5, 0}, {0, 0, 0}}; 201 | if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) { 202 | format = QImage::Format_RGB16; 203 | } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) { 204 | format = QImage::Format_RGB16; 205 | // pixeltype = BGRPixel; 206 | } 207 | break; 208 | } 209 | case 15: { 210 | const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0}, 211 | {0, 5, 0}, {15, 1, 0}}; 212 | const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0}, 213 | {10, 5, 0}, {15, 1, 0}}; 214 | if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) { 215 | format = QImage::Format_RGB555; 216 | } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) { 217 | format = QImage::Format_RGB555; 218 | // pixeltype = BGRPixel; 219 | } 220 | break; 221 | } 222 | case 12: { 223 | const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0}, 224 | {0, 4, 0}, {0, 0, 0}}; 225 | if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0) 226 | format = QImage::Format_RGB444; 227 | break; 228 | } 229 | case 8: 230 | break; 231 | case 1: 232 | format = QImage::Format_Mono; //###: LSB??? 233 | break; 234 | default: 235 | break; 236 | } 237 | 238 | return format; 239 | } 240 | 241 | static int openTtyDevice(const QString &device) 242 | { 243 | const char *const devs[] = { "/dev/tty0", "/dev/tty", "/dev/console", 0 }; 244 | 245 | int fd = -1; 246 | if (device.isEmpty()) { 247 | for (const char * const *dev = devs; *dev; ++dev) { 248 | fd = QT_OPEN(*dev, O_RDWR); 249 | if (fd != -1) 250 | break; 251 | } 252 | } else { 253 | fd = QT_OPEN(QFile::encodeName(device).constData(), O_RDWR); 254 | } 255 | 256 | return fd; 257 | } 258 | 259 | static bool switchToGraphicsMode(int ttyfd, int *oldMode) 260 | { 261 | ioctl(ttyfd, KDGETMODE, oldMode); 262 | if (*oldMode != KD_GRAPHICS) { 263 | if (ioctl(ttyfd, KDSETMODE, KD_GRAPHICS) != 0) 264 | return false; 265 | } 266 | 267 | return true; 268 | } 269 | 270 | static void resetTty(int ttyfd, int oldMode) 271 | { 272 | ioctl(ttyfd, KDSETMODE, oldMode); 273 | 274 | QT_CLOSE(ttyfd); 275 | } 276 | 277 | static void blankScreen(int fd, bool on) 278 | { 279 | ioctl(fd, FBIOBLANK, on ? VESA_POWERDOWN : VESA_NO_BLANKING); 280 | } 281 | 282 | QLinuxFbScreen::QLinuxFbScreen(const QStringList &args) 283 | : mArgs(args), mFbFd(-1), mBlitter(0), mRotation(90) 284 | { 285 | } 286 | 287 | QLinuxFbScreen::~QLinuxFbScreen() 288 | { 289 | if (mFbFd != -1) { 290 | munmap(mMmap.data - mMmap.offset, mMmap.size); 291 | close(mFbFd); 292 | } 293 | 294 | if (mTtyFd != -1) { 295 | resetTty(mTtyFd, mOldTtyMode); 296 | close(mTtyFd); 297 | } 298 | 299 | delete mBlitter; 300 | } 301 | 302 | bool QLinuxFbScreen::initialize() 303 | { 304 | QRegularExpression ttyRx(QLatin1String("tty=(.*)")); 305 | QRegularExpression fbRx(QLatin1String("fb=(.*)")); 306 | QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)")); 307 | QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); 308 | QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)")); 309 | QRegularExpression rotationRx(QLatin1String("rotation=(0|90|180|270)")); 310 | 311 | QString fbDevice, ttyDevice; 312 | QSize userMmSize; 313 | QRect userGeometry; 314 | bool doSwitchToGraphicsMode = true; 315 | 316 | // Parse arguments 317 | foreach (const QString &arg, mArgs) { 318 | QRegularExpressionMatch match; 319 | if (arg == QLatin1String("nographicsmodeswitch")) 320 | doSwitchToGraphicsMode = false; 321 | else if (arg.contains(mmSizeRx, &match)) 322 | userMmSize = QSize(match.captured(1).toInt(), match.captured(2).toInt()); 323 | else if (arg.contains(sizeRx, &match)) 324 | userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt())); 325 | else if (arg.contains(offsetRx, &match)) 326 | userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt())); 327 | else if (arg.contains(ttyRx, &match)) 328 | ttyDevice = match.captured(1); 329 | else if (arg.contains(fbRx, &match)) 330 | fbDevice = match.captured(1); 331 | else if (arg.contains(rotationRx, &match)) 332 | mRotation = match.captured(1).toInt(); 333 | } 334 | 335 | if (fbDevice.isEmpty()) { 336 | fbDevice = QLatin1String("/dev/fb0"); 337 | if (!QFile::exists(fbDevice)) 338 | fbDevice = QLatin1String("/dev/graphics/fb0"); 339 | if (!QFile::exists(fbDevice)) { 340 | qWarning("Unable to figure out framebuffer device. Specify it manually."); 341 | return false; 342 | } 343 | } 344 | 345 | // Open the device 346 | mFbFd = openFramebufferDevice(fbDevice); 347 | if (mFbFd == -1) { 348 | qErrnoWarning(errno, "Failed to open framebuffer %s", qPrintable(fbDevice)); 349 | return false; 350 | } 351 | 352 | // Read the fixed and variable screen information 353 | fb_fix_screeninfo finfo; 354 | fb_var_screeninfo vinfo; 355 | memset(&vinfo, 0, sizeof(vinfo)); 356 | memset(&finfo, 0, sizeof(finfo)); 357 | 358 | if (ioctl(mFbFd, FBIOGET_FSCREENINFO, &finfo) != 0) { 359 | qErrnoWarning(errno, "Error reading fixed information"); 360 | return false; 361 | } 362 | 363 | if (ioctl(mFbFd, FBIOGET_VSCREENINFO, &vinfo)) { 364 | qErrnoWarning(errno, "Error reading variable information"); 365 | return false; 366 | } 367 | 368 | mDepth = determineDepth(vinfo); 369 | mBytesPerLine = finfo.line_length; 370 | QRect geometry = determineGeometry(vinfo, userGeometry); 371 | QRect originalGeometry = geometry; 372 | if( mRotation == 90 || mRotation == 270 ) 373 | { 374 | int tmp = geometry.width(); 375 | geometry.setWidth(geometry.height()); 376 | geometry.setHeight(tmp); 377 | } 378 | mGeometry = QRect(QPoint(0, 0), geometry.size()); 379 | mFormat = determineFormat(vinfo, mDepth); 380 | mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, originalGeometry.size()); 381 | 382 | // mmap the framebuffer 383 | mMmap.size = finfo.smem_len; 384 | uchar *data = (unsigned char *)mmap(0, mMmap.size, PROT_READ | PROT_WRITE, MAP_SHARED, mFbFd, 0); 385 | if ((long)data == -1) { 386 | qErrnoWarning(errno, "Failed to mmap framebuffer"); 387 | return false; 388 | } 389 | 390 | mMmap.offset = originalGeometry.y() * mBytesPerLine + originalGeometry.x() * mDepth / 8; 391 | mMmap.data = data + mMmap.offset; 392 | 393 | QFbScreen::initializeCompositor(); 394 | mFbScreenImage = QImage(mMmap.data, originalGeometry.width(), originalGeometry.height(), mBytesPerLine, mFormat); 395 | 396 | mCursor = new QFbCursor(this); 397 | 398 | mTtyFd = openTtyDevice(ttyDevice); 399 | if (mTtyFd == -1) 400 | qErrnoWarning(errno, "Failed to open tty"); 401 | 402 | if (doSwitchToGraphicsMode) 403 | switchToGraphicsMode(mTtyFd, &mOldTtyMode); 404 | // Do not warn if the switch fails: the ioctl fails when launching from 405 | // a remote console and there is nothing we can do about it. 406 | 407 | blankScreen(mFbFd, false); 408 | 409 | return true; 410 | } 411 | 412 | QRegion QLinuxFbScreen::doRedraw() 413 | { 414 | QRegion touched = QFbScreen::doRedraw(); 415 | 416 | if (touched.isEmpty()) 417 | return touched; 418 | 419 | if (!mBlitter) 420 | mBlitter = new QPainter(&mFbScreenImage); 421 | 422 | QVector rects = touched.rects(); 423 | for (int i = 0; i < rects.size(); i++) 424 | { 425 | if( mRotation == 90 || mRotation == 270 ) 426 | { 427 | mBlitter->translate(mGeometry.height()/2, mGeometry.width()/2); 428 | } 429 | else if( mRotation == 180 ) 430 | { 431 | mBlitter->translate(mGeometry.width()/2, mGeometry.height()/2); 432 | } 433 | 434 | if( mRotation != 0 ) 435 | { 436 | mBlitter->rotate(mRotation); 437 | mBlitter->translate(-mGeometry.width()/2, -mGeometry.height()/2); 438 | } 439 | //edit by zc 440 | mBlitter->setCompositionMode(QPainter::CompositionMode_Source); 441 | mBlitter->drawImage(rects[i], *mScreenImage, rects[i]); 442 | mBlitter->resetTransform(); 443 | } 444 | return touched; 445 | } 446 | 447 | // grabWindow() grabs "from the screen" not from the backingstores. 448 | // In linuxfb's case it will also include the mouse cursor. 449 | QPixmap QLinuxFbScreen::grabWindow(WId wid, int x, int y, int width, int height) const 450 | { 451 | if (!wid) { 452 | if (width < 0) 453 | width = mFbScreenImage.width() - x; 454 | if (height < 0) 455 | height = mFbScreenImage.height() - y; 456 | return QPixmap::fromImage(mFbScreenImage).copy(x, y, width, height); 457 | } 458 | 459 | QFbWindow *window = windowForId(wid); 460 | if (window) { 461 | const QRect geom = window->geometry(); 462 | if (width < 0) 463 | width = geom.width() - x; 464 | if (height < 0) 465 | height = geom.height() - y; 466 | QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height)); 467 | rect &= window->geometry(); 468 | return QPixmap::fromImage(mFbScreenImage).copy(rect); 469 | } 470 | 471 | return QPixmap(); 472 | } 473 | 474 | QT_END_NAMESPACE 475 | 476 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp.bak: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #include "qlinuxfbscreen.h" 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include // overrides QT_OPEN 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | QT_BEGIN_NAMESPACE 60 | 61 | static int openFramebufferDevice(const QString &dev) 62 | { 63 | int fd = -1; 64 | 65 | if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0) 66 | fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR); 67 | 68 | if (fd == -1) { 69 | if (access(dev.toLatin1().constData(), R_OK) == 0) 70 | fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY); 71 | } 72 | 73 | return fd; 74 | } 75 | 76 | static int determineDepth(const fb_var_screeninfo &vinfo) 77 | { 78 | int depth = vinfo.bits_per_pixel; 79 | if (depth== 24) { 80 | depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; 81 | if (depth <= 0) 82 | depth = 24; // reset if color component lengths are not reported 83 | } else if (depth == 16) { 84 | depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; 85 | if (depth <= 0) 86 | depth = 16; 87 | } 88 | return depth; 89 | } 90 | 91 | static QRect determineGeometry(const fb_var_screeninfo &vinfo, const QRect &userGeometry) 92 | { 93 | int xoff = vinfo.xoffset; 94 | int yoff = vinfo.yoffset; 95 | int w, h; 96 | if (userGeometry.isValid()) { 97 | w = userGeometry.width(); 98 | h = userGeometry.height(); 99 | if ((uint)w > vinfo.xres) 100 | w = vinfo.xres; 101 | if ((uint)h > vinfo.yres) 102 | h = vinfo.yres; 103 | 104 | int xxoff = userGeometry.x(), yyoff = userGeometry.y(); 105 | if (xxoff != 0 || yyoff != 0) { 106 | if (xxoff < 0 || xxoff + w > (int)(vinfo.xres)) 107 | xxoff = vinfo.xres - w; 108 | if (yyoff < 0 || yyoff + h > (int)(vinfo.yres)) 109 | yyoff = vinfo.yres - h; 110 | xoff += xxoff; 111 | yoff += yyoff; 112 | } else { 113 | xoff += (vinfo.xres - w)/2; 114 | yoff += (vinfo.yres - h)/2; 115 | } 116 | } else { 117 | w = vinfo.xres; 118 | h = vinfo.yres; 119 | } 120 | 121 | if (w == 0 || h == 0) { 122 | qWarning("Unable to find screen geometry, using 320x240"); 123 | w = 320; 124 | h = 240; 125 | } 126 | 127 | return QRect(xoff, yoff, w, h); 128 | } 129 | 130 | static QSizeF determinePhysicalSize(const fb_var_screeninfo &vinfo, const QSize &mmSize, const QSize &res) 131 | { 132 | int mmWidth = mmSize.width(), mmHeight = mmSize.height(); 133 | 134 | if (mmWidth <= 0 && mmHeight <= 0) { 135 | if (vinfo.width != 0 && vinfo.height != 0 136 | && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) { 137 | mmWidth = vinfo.width; 138 | mmHeight = vinfo.height; 139 | } else { 140 | const int dpi = 100; 141 | mmWidth = qRound(res.width() * 25.4 / dpi); 142 | mmHeight = qRound(res.height() * 25.4 / dpi); 143 | } 144 | } else if (mmWidth > 0 && mmHeight <= 0) { 145 | mmHeight = res.height() * mmWidth/res.width(); 146 | } else if (mmHeight > 0 && mmWidth <= 0) { 147 | mmWidth = res.width() * mmHeight/res.height(); 148 | } 149 | 150 | return QSize(mmWidth, mmHeight); 151 | } 152 | 153 | static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth) 154 | { 155 | const fb_bitfield rgba[4] = { info.red, info.green, 156 | info.blue, info.transp }; 157 | 158 | QImage::Format format = QImage::Format_Invalid; 159 | 160 | switch (depth) { 161 | case 32: { 162 | const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0}, 163 | {0, 8, 0}, {24, 8, 0}}; 164 | const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0}, 165 | {16, 8, 0}, {24, 8, 0}}; 166 | if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) { 167 | format = QImage::Format_ARGB32; 168 | } else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) { 169 | format = QImage::Format_RGB32; 170 | } else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) { 171 | format = QImage::Format_RGB32; 172 | // pixeltype = BGRPixel; 173 | } 174 | break; 175 | } 176 | case 24: { 177 | const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0}, 178 | {0, 8, 0}, {0, 0, 0}}; 179 | const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0}, 180 | {16, 8, 0}, {0, 0, 0}}; 181 | if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) { 182 | format = QImage::Format_RGB888; 183 | } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) { 184 | format = QImage::Format_RGB888; 185 | // pixeltype = BGRPixel; 186 | } 187 | break; 188 | } 189 | case 18: { 190 | const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0}, 191 | {0, 6, 0}, {0, 0, 0}}; 192 | if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0) 193 | format = QImage::Format_RGB666; 194 | break; 195 | } 196 | case 16: { 197 | const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0}, 198 | {0, 5, 0}, {0, 0, 0}}; 199 | const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0}, 200 | {11, 5, 0}, {0, 0, 0}}; 201 | if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) { 202 | format = QImage::Format_RGB16; 203 | } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) { 204 | format = QImage::Format_RGB16; 205 | // pixeltype = BGRPixel; 206 | } 207 | break; 208 | } 209 | case 15: { 210 | const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0}, 211 | {0, 5, 0}, {15, 1, 0}}; 212 | const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0}, 213 | {10, 5, 0}, {15, 1, 0}}; 214 | if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) { 215 | format = QImage::Format_RGB555; 216 | } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) { 217 | format = QImage::Format_RGB555; 218 | // pixeltype = BGRPixel; 219 | } 220 | break; 221 | } 222 | case 12: { 223 | const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0}, 224 | {0, 4, 0}, {0, 0, 0}}; 225 | if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0) 226 | format = QImage::Format_RGB444; 227 | break; 228 | } 229 | case 8: 230 | break; 231 | case 1: 232 | format = QImage::Format_Mono; //###: LSB??? 233 | break; 234 | default: 235 | break; 236 | } 237 | 238 | return format; 239 | } 240 | 241 | static int openTtyDevice(const QString &device) 242 | { 243 | const char *const devs[] = { "/dev/tty0", "/dev/tty", "/dev/console", 0 }; 244 | 245 | int fd = -1; 246 | if (device.isEmpty()) { 247 | for (const char * const *dev = devs; *dev; ++dev) { 248 | fd = QT_OPEN(*dev, O_RDWR); 249 | if (fd != -1) 250 | break; 251 | } 252 | } else { 253 | fd = QT_OPEN(QFile::encodeName(device).constData(), O_RDWR); 254 | } 255 | 256 | return fd; 257 | } 258 | 259 | static bool switchToGraphicsMode(int ttyfd, int *oldMode) 260 | { 261 | ioctl(ttyfd, KDGETMODE, oldMode); 262 | if (*oldMode != KD_GRAPHICS) { 263 | if (ioctl(ttyfd, KDSETMODE, KD_GRAPHICS) != 0) 264 | return false; 265 | } 266 | 267 | return true; 268 | } 269 | 270 | static void resetTty(int ttyfd, int oldMode) 271 | { 272 | ioctl(ttyfd, KDSETMODE, oldMode); 273 | 274 | QT_CLOSE(ttyfd); 275 | } 276 | 277 | static void blankScreen(int fd, bool on) 278 | { 279 | ioctl(fd, FBIOBLANK, on ? VESA_POWERDOWN : VESA_NO_BLANKING); 280 | } 281 | 282 | QLinuxFbScreen::QLinuxFbScreen(const QStringList &args) 283 | : mArgs(args), mFbFd(-1), mBlitter(0) 284 | { 285 | } 286 | 287 | QLinuxFbScreen::~QLinuxFbScreen() 288 | { 289 | if (mFbFd != -1) { 290 | munmap(mMmap.data - mMmap.offset, mMmap.size); 291 | close(mFbFd); 292 | } 293 | 294 | if (mTtyFd != -1) { 295 | resetTty(mTtyFd, mOldTtyMode); 296 | close(mTtyFd); 297 | } 298 | 299 | delete mBlitter; 300 | } 301 | 302 | bool QLinuxFbScreen::initialize() 303 | { 304 | QRegularExpression ttyRx(QLatin1String("tty=(.*)")); 305 | QRegularExpression fbRx(QLatin1String("fb=(.*)")); 306 | QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)")); 307 | QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); 308 | QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)")); 309 | 310 | QString fbDevice, ttyDevice; 311 | QSize userMmSize; 312 | QRect userGeometry; 313 | bool doSwitchToGraphicsMode = true; 314 | 315 | // Parse arguments 316 | foreach (const QString &arg, mArgs) { 317 | QRegularExpressionMatch match; 318 | if (arg == QLatin1String("nographicsmodeswitch")) 319 | doSwitchToGraphicsMode = false; 320 | else if (arg.contains(mmSizeRx, &match)) 321 | userMmSize = QSize(match.captured(1).toInt(), match.captured(2).toInt()); 322 | else if (arg.contains(sizeRx, &match)) 323 | userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt())); 324 | else if (arg.contains(offsetRx, &match)) 325 | userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt())); 326 | else if (arg.contains(ttyRx, &match)) 327 | ttyDevice = match.captured(1); 328 | else if (arg.contains(fbRx, &match)) 329 | fbDevice = match.captured(1); 330 | } 331 | 332 | if (fbDevice.isEmpty()) { 333 | fbDevice = QLatin1String("/dev/fb0"); 334 | if (!QFile::exists(fbDevice)) 335 | fbDevice = QLatin1String("/dev/graphics/fb0"); 336 | if (!QFile::exists(fbDevice)) { 337 | qWarning("Unable to figure out framebuffer device. Specify it manually."); 338 | return false; 339 | } 340 | } 341 | 342 | // Open the device 343 | mFbFd = openFramebufferDevice(fbDevice); 344 | if (mFbFd == -1) { 345 | qErrnoWarning(errno, "Failed to open framebuffer %s", qPrintable(fbDevice)); 346 | return false; 347 | } 348 | 349 | // Read the fixed and variable screen information 350 | fb_fix_screeninfo finfo; 351 | fb_var_screeninfo vinfo; 352 | memset(&vinfo, 0, sizeof(vinfo)); 353 | memset(&finfo, 0, sizeof(finfo)); 354 | 355 | if (ioctl(mFbFd, FBIOGET_FSCREENINFO, &finfo) != 0) { 356 | qErrnoWarning(errno, "Error reading fixed information"); 357 | return false; 358 | } 359 | 360 | if (ioctl(mFbFd, FBIOGET_VSCREENINFO, &vinfo)) { 361 | qErrnoWarning(errno, "Error reading variable information"); 362 | return false; 363 | } 364 | 365 | mDepth = determineDepth(vinfo); 366 | mBytesPerLine = finfo.line_length; 367 | QRect geometry = determineGeometry(vinfo, userGeometry); 368 | mGeometry = QRect(QPoint(0, 0), geometry.size()); 369 | mFormat = determineFormat(vinfo, mDepth); 370 | mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, geometry.size()); 371 | 372 | // mmap the framebuffer 373 | mMmap.size = finfo.smem_len; 374 | uchar *data = (unsigned char *)mmap(0, mMmap.size, PROT_READ | PROT_WRITE, MAP_SHARED, mFbFd, 0); 375 | if ((long)data == -1) { 376 | qErrnoWarning(errno, "Failed to mmap framebuffer"); 377 | return false; 378 | } 379 | 380 | mMmap.offset = geometry.y() * mBytesPerLine + geometry.x() * mDepth / 8; 381 | mMmap.data = data + mMmap.offset; 382 | 383 | QFbScreen::initializeCompositor(); 384 | mFbScreenImage = QImage(mMmap.data, geometry.width(), geometry.height(), mBytesPerLine, mFormat); 385 | 386 | mCursor = new QFbCursor(this); 387 | 388 | mTtyFd = openTtyDevice(ttyDevice); 389 | if (mTtyFd == -1) 390 | qErrnoWarning(errno, "Failed to open tty"); 391 | 392 | if (doSwitchToGraphicsMode) 393 | switchToGraphicsMode(mTtyFd, &mOldTtyMode); 394 | // Do not warn if the switch fails: the ioctl fails when launching from 395 | // a remote console and there is nothing we can do about it. 396 | 397 | blankScreen(mFbFd, false); 398 | 399 | return true; 400 | } 401 | 402 | QRegion QLinuxFbScreen::doRedraw() 403 | { 404 | QRegion touched = QFbScreen::doRedraw(); 405 | 406 | if (touched.isEmpty()) 407 | return touched; 408 | 409 | if (!mBlitter) 410 | mBlitter = new QPainter(&mFbScreenImage); 411 | 412 | QVector rects = touched.rects(); 413 | for (int i = 0; i < rects.size(); i++) 414 | mBlitter->drawImage(rects[i], *mScreenImage, rects[i]); 415 | return touched; 416 | } 417 | 418 | // grabWindow() grabs "from the screen" not from the backingstores. 419 | // In linuxfb's case it will also include the mouse cursor. 420 | QPixmap QLinuxFbScreen::grabWindow(WId wid, int x, int y, int width, int height) const 421 | { 422 | if (!wid) { 423 | if (width < 0) 424 | width = mFbScreenImage.width() - x; 425 | if (height < 0) 426 | height = mFbScreenImage.height() - y; 427 | return QPixmap::fromImage(mFbScreenImage).copy(x, y, width, height); 428 | } 429 | 430 | QFbWindow *window = windowForId(wid); 431 | if (window) { 432 | const QRect geom = window->geometry(); 433 | if (width < 0) 434 | width = geom.width() - x; 435 | if (height < 0) 436 | height = geom.height() - y; 437 | QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height)); 438 | rect &= window->geometry(); 439 | return QPixmap::fromImage(mFbScreenImage).copy(rect); 440 | } 441 | 442 | return QPixmap(); 443 | } 444 | 445 | QT_END_NAMESPACE 446 | 447 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/plugins/platforms/linuxfb/qlinuxfbscreen.cpp_patch: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #include "qlinuxfbscreen.h" 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include // overrides QT_OPEN 41 | #include 42 | #include 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | QT_BEGIN_NAMESPACE 60 | 61 | static int openFramebufferDevice(const QString &dev) 62 | { 63 | int fd = -1; 64 | 65 | if (access(dev.toLatin1().constData(), R_OK|W_OK) == 0) 66 | fd = QT_OPEN(dev.toLatin1().constData(), O_RDWR); 67 | 68 | if (fd == -1) { 69 | if (access(dev.toLatin1().constData(), R_OK) == 0) 70 | fd = QT_OPEN(dev.toLatin1().constData(), O_RDONLY); 71 | } 72 | 73 | return fd; 74 | } 75 | 76 | static int determineDepth(const fb_var_screeninfo &vinfo) 77 | { 78 | int depth = vinfo.bits_per_pixel; 79 | if (depth== 24) { 80 | depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; 81 | if (depth <= 0) 82 | depth = 24; // reset if color component lengths are not reported 83 | } else if (depth == 16) { 84 | depth = vinfo.red.length + vinfo.green.length + vinfo.blue.length; 85 | if (depth <= 0) 86 | depth = 16; 87 | } 88 | return depth; 89 | } 90 | 91 | static QRect determineGeometry(const fb_var_screeninfo &vinfo, const QRect &userGeometry) 92 | { 93 | int xoff = vinfo.xoffset; 94 | int yoff = vinfo.yoffset; 95 | int w, h; 96 | if (userGeometry.isValid()) { 97 | w = userGeometry.width(); 98 | h = userGeometry.height(); 99 | if ((uint)w > vinfo.xres) 100 | w = vinfo.xres; 101 | if ((uint)h > vinfo.yres) 102 | h = vinfo.yres; 103 | 104 | int xxoff = userGeometry.x(), yyoff = userGeometry.y(); 105 | if (xxoff != 0 || yyoff != 0) { 106 | if (xxoff < 0 || xxoff + w > (int)(vinfo.xres)) 107 | xxoff = vinfo.xres - w; 108 | if (yyoff < 0 || yyoff + h > (int)(vinfo.yres)) 109 | yyoff = vinfo.yres - h; 110 | xoff += xxoff; 111 | yoff += yyoff; 112 | } else { 113 | xoff += (vinfo.xres - w)/2; 114 | yoff += (vinfo.yres - h)/2; 115 | } 116 | } else { 117 | w = vinfo.xres; 118 | h = vinfo.yres; 119 | } 120 | 121 | if (w == 0 || h == 0) { 122 | qWarning("Unable to find screen geometry, using 320x240"); 123 | w = 320; 124 | h = 240; 125 | } 126 | 127 | return QRect(xoff, yoff, w, h); 128 | } 129 | 130 | static QSizeF determinePhysicalSize(const fb_var_screeninfo &vinfo, const QSize &mmSize, const QSize &res) 131 | { 132 | int mmWidth = mmSize.width(), mmHeight = mmSize.height(); 133 | 134 | if (mmWidth <= 0 && mmHeight <= 0) { 135 | if (vinfo.width != 0 && vinfo.height != 0 136 | && vinfo.width != UINT_MAX && vinfo.height != UINT_MAX) { 137 | mmWidth = vinfo.width; 138 | mmHeight = vinfo.height; 139 | } else { 140 | const int dpi = 100; 141 | mmWidth = qRound(res.width() * 25.4 / dpi); 142 | mmHeight = qRound(res.height() * 25.4 / dpi); 143 | } 144 | } else if (mmWidth > 0 && mmHeight <= 0) { 145 | mmHeight = res.height() * mmWidth/res.width(); 146 | } else if (mmHeight > 0 && mmWidth <= 0) { 147 | mmWidth = res.width() * mmHeight/res.height(); 148 | } 149 | 150 | return QSize(mmWidth, mmHeight); 151 | } 152 | 153 | static QImage::Format determineFormat(const fb_var_screeninfo &info, int depth) 154 | { 155 | const fb_bitfield rgba[4] = { info.red, info.green, 156 | info.blue, info.transp }; 157 | 158 | QImage::Format format = QImage::Format_Invalid; 159 | 160 | switch (depth) { 161 | case 32: { 162 | const fb_bitfield argb8888[4] = {{16, 8, 0}, {8, 8, 0}, 163 | {0, 8, 0}, {24, 8, 0}}; 164 | const fb_bitfield abgr8888[4] = {{0, 8, 0}, {8, 8, 0}, 165 | {16, 8, 0}, {24, 8, 0}}; 166 | if (memcmp(rgba, argb8888, 4 * sizeof(fb_bitfield)) == 0) { 167 | format = QImage::Format_ARGB32; 168 | } else if (memcmp(rgba, argb8888, 3 * sizeof(fb_bitfield)) == 0) { 169 | format = QImage::Format_RGB32; 170 | } else if (memcmp(rgba, abgr8888, 3 * sizeof(fb_bitfield)) == 0) { 171 | format = QImage::Format_RGB32; 172 | // pixeltype = BGRPixel; 173 | } 174 | break; 175 | } 176 | case 24: { 177 | const fb_bitfield rgb888[4] = {{16, 8, 0}, {8, 8, 0}, 178 | {0, 8, 0}, {0, 0, 0}}; 179 | const fb_bitfield bgr888[4] = {{0, 8, 0}, {8, 8, 0}, 180 | {16, 8, 0}, {0, 0, 0}}; 181 | if (memcmp(rgba, rgb888, 3 * sizeof(fb_bitfield)) == 0) { 182 | format = QImage::Format_RGB888; 183 | } else if (memcmp(rgba, bgr888, 3 * sizeof(fb_bitfield)) == 0) { 184 | format = QImage::Format_RGB888; 185 | // pixeltype = BGRPixel; 186 | } 187 | break; 188 | } 189 | case 18: { 190 | const fb_bitfield rgb666[4] = {{12, 6, 0}, {6, 6, 0}, 191 | {0, 6, 0}, {0, 0, 0}}; 192 | if (memcmp(rgba, rgb666, 3 * sizeof(fb_bitfield)) == 0) 193 | format = QImage::Format_RGB666; 194 | break; 195 | } 196 | case 16: { 197 | const fb_bitfield rgb565[4] = {{11, 5, 0}, {5, 6, 0}, 198 | {0, 5, 0}, {0, 0, 0}}; 199 | const fb_bitfield bgr565[4] = {{0, 5, 0}, {5, 6, 0}, 200 | {11, 5, 0}, {0, 0, 0}}; 201 | if (memcmp(rgba, rgb565, 3 * sizeof(fb_bitfield)) == 0) { 202 | format = QImage::Format_RGB16; 203 | } else if (memcmp(rgba, bgr565, 3 * sizeof(fb_bitfield)) == 0) { 204 | format = QImage::Format_RGB16; 205 | // pixeltype = BGRPixel; 206 | } 207 | break; 208 | } 209 | case 15: { 210 | const fb_bitfield rgb1555[4] = {{10, 5, 0}, {5, 5, 0}, 211 | {0, 5, 0}, {15, 1, 0}}; 212 | const fb_bitfield bgr1555[4] = {{0, 5, 0}, {5, 5, 0}, 213 | {10, 5, 0}, {15, 1, 0}}; 214 | if (memcmp(rgba, rgb1555, 3 * sizeof(fb_bitfield)) == 0) { 215 | format = QImage::Format_RGB555; 216 | } else if (memcmp(rgba, bgr1555, 3 * sizeof(fb_bitfield)) == 0) { 217 | format = QImage::Format_RGB555; 218 | // pixeltype = BGRPixel; 219 | } 220 | break; 221 | } 222 | case 12: { 223 | const fb_bitfield rgb444[4] = {{8, 4, 0}, {4, 4, 0}, 224 | {0, 4, 0}, {0, 0, 0}}; 225 | if (memcmp(rgba, rgb444, 3 * sizeof(fb_bitfield)) == 0) 226 | format = QImage::Format_RGB444; 227 | break; 228 | } 229 | case 8: 230 | break; 231 | case 1: 232 | format = QImage::Format_Mono; //###: LSB??? 233 | break; 234 | default: 235 | break; 236 | } 237 | 238 | return format; 239 | } 240 | 241 | static int openTtyDevice(const QString &device) 242 | { 243 | const char *const devs[] = { "/dev/tty0", "/dev/tty", "/dev/console", 0 }; 244 | 245 | int fd = -1; 246 | if (device.isEmpty()) { 247 | for (const char * const *dev = devs; *dev; ++dev) { 248 | fd = QT_OPEN(*dev, O_RDWR); 249 | if (fd != -1) 250 | break; 251 | } 252 | } else { 253 | fd = QT_OPEN(QFile::encodeName(device).constData(), O_RDWR); 254 | } 255 | 256 | return fd; 257 | } 258 | 259 | static bool switchToGraphicsMode(int ttyfd, int *oldMode) 260 | { 261 | ioctl(ttyfd, KDGETMODE, oldMode); 262 | if (*oldMode != KD_GRAPHICS) { 263 | if (ioctl(ttyfd, KDSETMODE, KD_GRAPHICS) != 0) 264 | return false; 265 | } 266 | 267 | return true; 268 | } 269 | 270 | static void resetTty(int ttyfd, int oldMode) 271 | { 272 | ioctl(ttyfd, KDSETMODE, oldMode); 273 | 274 | QT_CLOSE(ttyfd); 275 | } 276 | 277 | static void blankScreen(int fd, bool on) 278 | { 279 | ioctl(fd, FBIOBLANK, on ? VESA_POWERDOWN : VESA_NO_BLANKING); 280 | } 281 | 282 | QLinuxFbScreen::QLinuxFbScreen(const QStringList &args) 283 | : mArgs(args), mFbFd(-1), mBlitter(0), mRotation(90) 284 | { 285 | } 286 | 287 | QLinuxFbScreen::~QLinuxFbScreen() 288 | { 289 | if (mFbFd != -1) { 290 | munmap(mMmap.data - mMmap.offset, mMmap.size); 291 | close(mFbFd); 292 | } 293 | 294 | if (mTtyFd != -1) { 295 | resetTty(mTtyFd, mOldTtyMode); 296 | close(mTtyFd); 297 | } 298 | 299 | delete mBlitter; 300 | } 301 | 302 | bool QLinuxFbScreen::initialize() 303 | { 304 | QRegularExpression ttyRx(QLatin1String("tty=(.*)")); 305 | QRegularExpression fbRx(QLatin1String("fb=(.*)")); 306 | QRegularExpression mmSizeRx(QLatin1String("mmsize=(\\d+)x(\\d+)")); 307 | QRegularExpression sizeRx(QLatin1String("size=(\\d+)x(\\d+)")); 308 | QRegularExpression offsetRx(QLatin1String("offset=(\\d+)x(\\d+)")); 309 | QRegularExpression rotationRx(QLatin1String("rotation=(0|90|180|270)")); 310 | 311 | QString fbDevice, ttyDevice; 312 | QSize userMmSize; 313 | QRect userGeometry; 314 | bool doSwitchToGraphicsMode = true; 315 | 316 | // Parse arguments 317 | foreach (const QString &arg, mArgs) { 318 | QRegularExpressionMatch match; 319 | if (arg == QLatin1String("nographicsmodeswitch")) 320 | doSwitchToGraphicsMode = false; 321 | else if (arg.contains(mmSizeRx, &match)) 322 | userMmSize = QSize(match.captured(1).toInt(), match.captured(2).toInt()); 323 | else if (arg.contains(sizeRx, &match)) 324 | userGeometry.setSize(QSize(match.captured(1).toInt(), match.captured(2).toInt())); 325 | else if (arg.contains(offsetRx, &match)) 326 | userGeometry.setTopLeft(QPoint(match.captured(1).toInt(), match.captured(2).toInt())); 327 | else if (arg.contains(ttyRx, &match)) 328 | ttyDevice = match.captured(1); 329 | else if (arg.contains(fbRx, &match)) 330 | fbDevice = match.captured(1); 331 | else if (arg.contains(rotationRx, &match)) 332 | mRotation = match.captured(1).toInt(); 333 | } 334 | 335 | if (fbDevice.isEmpty()) { 336 | fbDevice = QLatin1String("/dev/fb0"); 337 | if (!QFile::exists(fbDevice)) 338 | fbDevice = QLatin1String("/dev/graphics/fb0"); 339 | if (!QFile::exists(fbDevice)) { 340 | qWarning("Unable to figure out framebuffer device. Specify it manually."); 341 | return false; 342 | } 343 | } 344 | 345 | // Open the device 346 | mFbFd = openFramebufferDevice(fbDevice); 347 | if (mFbFd == -1) { 348 | qErrnoWarning(errno, "Failed to open framebuffer %s", qPrintable(fbDevice)); 349 | return false; 350 | } 351 | 352 | // Read the fixed and variable screen information 353 | fb_fix_screeninfo finfo; 354 | fb_var_screeninfo vinfo; 355 | memset(&vinfo, 0, sizeof(vinfo)); 356 | memset(&finfo, 0, sizeof(finfo)); 357 | 358 | if (ioctl(mFbFd, FBIOGET_FSCREENINFO, &finfo) != 0) { 359 | qErrnoWarning(errno, "Error reading fixed information"); 360 | return false; 361 | } 362 | 363 | if (ioctl(mFbFd, FBIOGET_VSCREENINFO, &vinfo)) { 364 | qErrnoWarning(errno, "Error reading variable information"); 365 | return false; 366 | } 367 | 368 | mDepth = determineDepth(vinfo); 369 | mBytesPerLine = finfo.line_length; 370 | QRect geometry = determineGeometry(vinfo, userGeometry); 371 | QRect originalGeometry = geometry; 372 | if( mRotation == 90 || mRotation == 270 ) 373 | { 374 | int tmp = geometry.width(); 375 | geometry.setWidth(geometry.height()); 376 | geometry.setHeight(tmp); 377 | } 378 | mGeometry = QRect(QPoint(0, 0), geometry.size()); 379 | mFormat = determineFormat(vinfo, mDepth); 380 | mPhysicalSize = determinePhysicalSize(vinfo, userMmSize, originalGeometry.size()); 381 | 382 | // mmap the framebuffer 383 | mMmap.size = finfo.smem_len; 384 | uchar *data = (unsigned char *)mmap(0, mMmap.size, PROT_READ | PROT_WRITE, MAP_SHARED, mFbFd, 0); 385 | if ((long)data == -1) { 386 | qErrnoWarning(errno, "Failed to mmap framebuffer"); 387 | return false; 388 | } 389 | 390 | mMmap.offset = originalGeometry.y() * mBytesPerLine + originalGeometry.x() * mDepth / 8; 391 | mMmap.data = data + mMmap.offset; 392 | 393 | QFbScreen::initializeCompositor(); 394 | mFbScreenImage = QImage(mMmap.data, originalGeometry.width(), originalGeometry.height(), mBytesPerLine, mFormat); 395 | 396 | mCursor = new QFbCursor(this); 397 | 398 | mTtyFd = openTtyDevice(ttyDevice); 399 | if (mTtyFd == -1) 400 | qErrnoWarning(errno, "Failed to open tty"); 401 | 402 | if (doSwitchToGraphicsMode) 403 | switchToGraphicsMode(mTtyFd, &mOldTtyMode); 404 | // Do not warn if the switch fails: the ioctl fails when launching from 405 | // a remote console and there is nothing we can do about it. 406 | 407 | blankScreen(mFbFd, false); 408 | 409 | return true; 410 | } 411 | 412 | QRegion QLinuxFbScreen::doRedraw() 413 | { 414 | QRegion touched = QFbScreen::doRedraw(); 415 | 416 | if (touched.isEmpty()) 417 | return touched; 418 | 419 | if (!mBlitter) 420 | mBlitter = new QPainter(&mFbScreenImage); 421 | 422 | QVector rects = touched.rects(); 423 | for (int i = 0; i < rects.size(); i++) 424 | { 425 | if( mRotation == 90 || mRotation == 270 ) 426 | { 427 | mBlitter->translate(mGeometry.height()/2, mGeometry.width()/2); 428 | } 429 | else if( mRotation == 180 ) 430 | { 431 | mBlitter->translate(mGeometry.width()/2, mGeometry.height()/2); 432 | } 433 | 434 | if( mRotation != 0 ) 435 | { 436 | mBlitter->rotate(mRotation); 437 | mBlitter->translate(-mGeometry.width()/2, -mGeometry.height()/2); 438 | } 439 | 440 | mBlitter->drawImage(rects[i], *mScreenImage, rects[i]); 441 | 442 | mBlitter->resetTransform(); 443 | } 444 | return touched; 445 | } 446 | 447 | // grabWindow() grabs "from the screen" not from the backingstores. 448 | // In linuxfb's case it will also include the mouse cursor. 449 | QPixmap QLinuxFbScreen::grabWindow(WId wid, int x, int y, int width, int height) const 450 | { 451 | if (!wid) { 452 | if (width < 0) 453 | width = mFbScreenImage.width() - x; 454 | if (height < 0) 455 | height = mFbScreenImage.height() - y; 456 | return QPixmap::fromImage(mFbScreenImage).copy(x, y, width, height); 457 | } 458 | 459 | QFbWindow *window = windowForId(wid); 460 | if (window) { 461 | const QRect geom = window->geometry(); 462 | if (width < 0) 463 | width = geom.width() - x; 464 | if (height < 0) 465 | height = geom.height() - y; 466 | QRect rect(geom.topLeft() + QPoint(x, y), QSize(width, height)); 467 | rect &= window->geometry(); 468 | return QPixmap::fromImage(mFbScreenImage).copy(rect); 469 | } 470 | 471 | return QPixmap(); 472 | } 473 | 474 | QT_END_NAMESPACE 475 | 476 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/plugins/platforms/linuxfb/qlinuxfbscreen.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #ifndef QLINUXFBSCREEN_H 35 | #define QLINUXFBSCREEN_H 36 | 37 | #include 38 | 39 | QT_BEGIN_NAMESPACE 40 | 41 | class QPainter; 42 | class QFbCursor; 43 | 44 | class QLinuxFbScreen : public QFbScreen 45 | { 46 | Q_OBJECT 47 | public: 48 | QLinuxFbScreen(const QStringList &args); 49 | ~QLinuxFbScreen(); 50 | 51 | bool initialize(); 52 | 53 | QPixmap grabWindow(WId wid, int x, int y, int width, int height) const Q_DECL_OVERRIDE; 54 | 55 | QRegion doRedraw() Q_DECL_OVERRIDE; 56 | 57 | private: 58 | QStringList mArgs; 59 | int mFbFd; 60 | int mTtyFd; 61 | 62 | QImage mFbScreenImage; 63 | int mBytesPerLine; 64 | int mOldTtyMode; 65 | int mRotation; 66 | 67 | struct { 68 | uchar *data; 69 | int offset, size; 70 | } mMmap; 71 | 72 | QPainter *mBlitter; 73 | }; 74 | 75 | QT_END_NAMESPACE 76 | 77 | #endif // QLINUXFBSCREEN_H 78 | 79 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/plugins/platforms/linuxfb/qlinuxfbscreen.h.bak: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #ifndef QLINUXFBSCREEN_H 35 | #define QLINUXFBSCREEN_H 36 | 37 | #include 38 | 39 | QT_BEGIN_NAMESPACE 40 | 41 | class QPainter; 42 | class QFbCursor; 43 | 44 | class QLinuxFbScreen : public QFbScreen 45 | { 46 | Q_OBJECT 47 | public: 48 | QLinuxFbScreen(const QStringList &args); 49 | ~QLinuxFbScreen(); 50 | 51 | bool initialize(); 52 | 53 | QPixmap grabWindow(WId wid, int x, int y, int width, int height) const Q_DECL_OVERRIDE; 54 | 55 | QRegion doRedraw() Q_DECL_OVERRIDE; 56 | 57 | private: 58 | QStringList mArgs; 59 | int mFbFd; 60 | int mTtyFd; 61 | 62 | QImage mFbScreenImage; 63 | int mBytesPerLine; 64 | int mOldTtyMode; 65 | 66 | struct { 67 | uchar *data; 68 | int offset, size; 69 | } mMmap; 70 | 71 | QPainter *mBlitter; 72 | }; 73 | 74 | QT_END_NAMESPACE 75 | 76 | #endif // QLINUXFBSCREEN_H 77 | 78 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/qt5.5.1_enable_rotate_transprant/qtbase/src/plugins/platforms/linuxfb/qlinuxfbscreen.h_patch: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 The Qt Company Ltd. 4 | ** Contact: http://www.qt.io/licensing/ 5 | ** 6 | ** This file is part of the plugins of the Qt Toolkit. 7 | ** 8 | ** $QT_BEGIN_LICENSE:LGPL21$ 9 | ** Commercial License Usage 10 | ** Licensees holding valid commercial Qt licenses may use this file in 11 | ** accordance with the commercial license agreement provided with the 12 | ** Software or, alternatively, in accordance with the terms contained in 13 | ** a written agreement between you and The Qt Company. For licensing terms 14 | ** and conditions see http://www.qt.io/terms-conditions. For further 15 | ** information use the contact form at http://www.qt.io/contact-us. 16 | ** 17 | ** GNU Lesser General Public License Usage 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 or version 3 as published by the Free 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 | ** following information to ensure the GNU Lesser General Public License 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 | ** 26 | ** As a special exception, The Qt Company gives you certain additional 27 | ** rights. These rights are described in The Qt Company LGPL Exception 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 | ** 30 | ** $QT_END_LICENSE$ 31 | ** 32 | ****************************************************************************/ 33 | 34 | #ifndef QLINUXFBSCREEN_H 35 | #define QLINUXFBSCREEN_H 36 | 37 | #include 38 | 39 | QT_BEGIN_NAMESPACE 40 | 41 | class QPainter; 42 | class QFbCursor; 43 | 44 | class QLinuxFbScreen : public QFbScreen 45 | { 46 | Q_OBJECT 47 | public: 48 | QLinuxFbScreen(const QStringList &args); 49 | ~QLinuxFbScreen(); 50 | 51 | bool initialize(); 52 | 53 | QPixmap grabWindow(WId wid, int x, int y, int width, int height) const Q_DECL_OVERRIDE; 54 | 55 | QRegion doRedraw() Q_DECL_OVERRIDE; 56 | 57 | private: 58 | QStringList mArgs; 59 | int mFbFd; 60 | int mTtyFd; 61 | 62 | QImage mFbScreenImage; 63 | int mBytesPerLine; 64 | int mOldTtyMode; 65 | int mRotation; 66 | 67 | struct { 68 | uchar *data; 69 | int offset, size; 70 | } mMmap; 71 | 72 | QPainter *mBlitter; 73 | }; 74 | 75 | QT_END_NAMESPACE 76 | 77 | #endif // QLINUXFBSCREEN_H 78 | 79 | -------------------------------------------------------------------------------- /other/QtRotatingInArmForQt5/readme.cn: -------------------------------------------------------------------------------- 1 | 功能: 2 | 解决 qt5.5 linuxfb 下无法旋转程序的问题。 3 | 以及根据旋转补丁包修改源码后导致透明失效的问题。 4 | (旋转补丁包可以网络搜索获取, 这里的都为改好的了) 5 | 6 | 使能旋转透明后不黑底 7 | 使能程序旋转 8 | 实际使用的版本 qt.5.5.1 需要修改 platformsupport (使能旋转透明) 9 | 和 plugins (使能旋转) 两个文件夹下的文件 10 | 11 | 实际使用的版本 qt5.9.9 则只需要修改 plugins 文件夹下的文件即可 12 | 13 | 使用 qt.5.5.1 的时候发现了报错 "网络被禁用",好像是一个 bug,虽 14 | 然被修复了,但是既然要修改源码,干脆直接用新的版本好了 15 | 16 | 17 | 18 | 19 | date: 2021-01-29 20 | author: hehj 21 | 22 | -------------------------------------------------------------------------------- /qtproject.pro: -------------------------------------------------------------------------------- 1 | #CONFIG += ordered 2 | 3 | SUBDIRS = \ 4 | QtVirtualKeyboard/useKeyBoard_Demo \ 5 | QtVirtualKeyboard/makeChinesePY_db \ 6 | QtPagingToolBar/PagingToolBar \ 7 | QtSliptBotton/SliptBotton \ 8 | QtDrawingBoard/DrawingBoard \ 9 | QtTimer/Timer 10 | 11 | ## 设置构建目录为 build 目录 12 | #for(SUBDIR, SUBDIRS) { 13 | # $${SUBDIR}.target = $${SUBDIR} 14 | # $${SUBDIR}.target.path = $$OUT_PWD/build/$${SUBDIR} 15 | #} 16 | 17 | TEMPLATE = subdirs 18 | --------------------------------------------------------------------------------