├── .github └── workflows │ └── windows.yml ├── .gitignore ├── ColorItem.cpp ├── ColorItem.h ├── LICENSE ├── LinePaint.cpp ├── LinePaint.h ├── PointSizeWidget.cpp ├── PointSizeWidget.h ├── README.md ├── RectPaint.cpp ├── RectPaint.h ├── TextPaint.cpp ├── TextPaint.h ├── doc ├── f1.gif ├── f2.gif ├── f3.gif ├── f4.gif ├── f5.gif ├── main.png ├── main1.png └── main2.png ├── image ├── BROOK.ico ├── LUFFY.ico ├── ScreenShot20181209_203102.jpg ├── ZORO.ico ├── add.ico ├── add.png ├── brush.png ├── comp.ico ├── copy.png ├── drawellipse.png ├── drawline.png ├── drawrect.png ├── drawtext.png ├── file.png ├── folder.png ├── mail.ico ├── main.ico ├── remove.ico ├── remove.png ├── save.png ├── steam.ico ├── title.ico └── title.png ├── imageview.cpp ├── imageview.h ├── main.cpp ├── qtt.pri ├── qtt.pro ├── qtt.qrc ├── qtt.rc ├── qxtglobal.h ├── qxtglobalshortcut.cpp ├── qxtglobalshortcut.h ├── qxtglobalshortcut_p.h ├── qxtglobalshortcut_win.cpp ├── screenview.cpp ├── screenview.h ├── snappit.cpp ├── snappit.h ├── snappit.ui ├── struct.h ├── third party └── glog │ ├── include │ ├── glog │ │ ├── log_severity.h │ │ └── vlog_is_on.h │ ├── logging.h │ ├── raw_logging.h │ └── stl_logging.h │ └── lib │ └── win32 │ ├── glog.lib │ └── glogd.lib └── translation ├── qtt_en.qm ├── qtt_en.ts ├── qtt_zh.qm └── qtt_zh.ts /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: windows 4 | 5 | # Controls when the action will run. Triggers the workflow on push or pull request 6 | # events but only for the master branch 7 | on: 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | create: 13 | tags: 14 | 15 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 16 | jobs: 17 | # This workflow contains a single job called "build" 18 | build: 19 | # The type of runner that the job will run on 20 | runs-on: windows-latest 21 | strategy: 22 | matrix: 23 | qt_ver: [5.12.6] 24 | qt_target: [desktop] 25 | qt_arch: [win64_msvc2017_64, win32_msvc2017] 26 | include: 27 | - qt_arch: win64_msvc2017_64 28 | msvc_arch: x64 29 | - qt_arch: win32_msvc2017 30 | msvc_arch: x86 31 | env: 32 | targetName: screenshot.exe 33 | # Steps represent a sequence of tasks that will be executed as part of the job 34 | steps: 35 | #Cache Qt 36 | - name: cacheQt 37 | id: WindowsCacheQt 38 | uses: actions/cache@v1 39 | with: 40 | path: ../Qt/${{matrix.qt_ver}}/${{matrix.qt_arch_install}} 41 | key: ${{ runner.os }}-Qt/${{matrix.qt_ver}}/${{matrix.qt_arch}} 42 | # install Qt 43 | - name: Install Qt 44 | uses : jurplel/install-qt-action@v2.5.3 45 | with : 46 | version: ${{matrix.qt_ver}} 47 | target: ${{matrix.qt_target}} 48 | arch: ${{matrix.qt_arch}} 49 | mirror: http://mirrors.ocf.berkeley.edu/qt/ 50 | cached: ${{steps.WindowsCacheQt.outputs.cache-hit }} 51 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 52 | - uses: actions/checkout@v1 53 | with: 54 | fetch-depth: 1 55 | - name: build_msvc 56 | shell: cmd 57 | env: 58 | vc_arch: ${{matrix.msvc_arch}} 59 | run: | 60 | call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %vc_arch% 61 | qmake 62 | nmake 63 | # tag 打包 64 | - name: package 65 | env: 66 | VCINSTALLDIR: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC' 67 | archiveName: ${{ matrix.qt_ver }}-${{ matrix.qt_target }}-${{ matrix.qt_arch }} 68 | targetName: screenshot.exe 69 | shell: pwsh 70 | run: | 71 | # 创建文件夹 72 | New-Item -ItemType Directory ${env:archiveName} 73 | # 拷贝exe 74 | Copy-Item bin\${env:targetName} ${env:archiveName}\ 75 | # 拷贝依赖 76 | windeployqt --qmldir . ${env:archiveName}\${env:targetName} 77 | # 打包zip 78 | Compress-Archive -Path ${env:archiveName} ${env:archiveName}'.zip' 79 | # 记录环境变量packageName给后续step 80 | $name = ${env:archiveName} 81 | echo "::set-env name=packageName::$name" 82 | # 打印环境变量packageName 83 | Write-Host 'packageName:'${env:packageName} 84 | # tag 查询github-Release 85 | - name: queryReleaseWin 86 | id: queryReleaseWin 87 | shell: pwsh 88 | env: 89 | githubFullName: ${{ github.event.repository.full_name }} 90 | ref: ${{ github.event.ref }} 91 | run: | 92 | [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1) 93 | [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag} 94 | $response={} 95 | try { 96 | $response = Invoke-RestMethod -Uri $url -Method Get 97 | } catch { 98 | Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 99 | Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription 100 | # 没查到,输出 101 | echo "::set-output name=needCreateRelease::true" 102 | return 103 | } 104 | [string]$latestUpUrl = $response.upload_url 105 | Write-Host 'latestUpUrl:'$latestUpUrl 106 | if ($latestUpUrl.Length -eq 0) { 107 | # 没查到,输出 108 | echo "::set-output name=needCreateRelease::true" 109 | } 110 | # tag 创建github-Release 111 | - name: createReleaseWin 112 | id: createReleaseWin 113 | if: steps.queryReleaseWin.outputs.needCreateRelease == 'true' 114 | env: 115 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 116 | uses: actions/create-release@v1.0.0 117 | with: 118 | tag_name: ${{ github.ref }} 119 | release_name: Release ${{ github.ref }} 120 | body: ${{ github.event.head_commit.message }} 121 | draft: false 122 | prerelease: false 123 | # 重定向upload_url到环境变量uploadUrl。 124 | - name: getLatestTagRelease 125 | # tag 上一步无论成功还是失败都执行 126 | shell: pwsh 127 | env: 128 | githubFullName: ${{ github.event.repository.full_name }} 129 | upUrl: ${{ steps.createReleaseWin.outputs.upload_url }} 130 | ref: ${{ github.event.ref }} 131 | run: | 132 | # upUrl不为空,导出就完事 133 | if (${env:upUrl}.Length -gt 0) { 134 | $v=${env:upUrl} 135 | echo "::set-env name=uploadUrl::$v" 136 | return 137 | } 138 | [string]$tag = ${env:ref}.Substring(${env:ref}.LastIndexOf('/') + 1) 139 | [string]$url = 'https://api.github.com/repos/' + ${env:githubFullName} + '/releases/tags/' + ${tag} 140 | $response = Invoke-RestMethod -Uri $url -Method Get 141 | [string]$latestUpUrl = $response.upload_url 142 | Write-Host 'latestUpUrl:'$latestUpUrl 143 | echo "::set-env name=uploadUrl::$latestUpUrl" 144 | Write-Host 'env uploadUrl:'${env:uploadUrl} 145 | # tag 上传Release 146 | - name: uploadRelease 147 | id: uploadRelease 148 | env: 149 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 150 | uses: actions/upload-release-asset@v1.0.1 151 | with: 152 | upload_url: ${{ env.uploadUrl }} 153 | asset_path: ./${{ env.packageName }}.zip 154 | asset_name: ${{ env.packageName }}.zip 155 | asset_content_type: application/zip 156 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.vcxproj 2 | *.filters 3 | *.user 4 | *.aps 5 | 6 | Debug/ 7 | GeneratedFiles/ 8 | Release/ -------------------------------------------------------------------------------- /ColorItem.cpp: -------------------------------------------------------------------------------- 1 | #include "ColorItem.h" 2 | #include 3 | 4 | ColorItem::ColorItem(const QColor &color, int item_length /*= ITEM_LENGTH*/, QWidget *parent /*= 0*/) 5 | : QLabel(parent), _item_length(item_length) 6 | { 7 | _bMouseIn = false; 8 | setFixedSize(_item_length, _item_length); 9 | setColor(color); 10 | } 11 | 12 | ColorItem::~ColorItem() 13 | { 14 | 15 | } 16 | 17 | void ColorItem::setColor(const QColor &color) 18 | { 19 | _color = color; 20 | QImage itemImg = QImage(_item_length, _item_length, QImage::Format_RGB32); 21 | QPainter painter(&itemImg); 22 | painter.setRenderHint(QPainter::Antialiasing); 23 | painter.setCompositionMode(QPainter::CompositionMode_Source); 24 | painter.drawImage(0, 0, itemImg); 25 | painter.setPen(QPen(Qt::NoPen)); 26 | painter.setBrush(color); 27 | painter.drawRect(0, 0, _item_length, _item_length); 28 | setPixmap(QPixmap::fromImage(itemImg)); 29 | painter.setPen(QPen(Qt::black, 2)); 30 | painter.drawRect(1, 1, _item_length - 2, _item_length - 2); 31 | update(); 32 | } 33 | 34 | QColor ColorItem::getColor() const 35 | { 36 | return _color; 37 | } 38 | 39 | void ColorItem::mousePressEvent(QMouseEvent *event) 40 | { 41 | emit itemClicked(_color); 42 | emit clicked(); 43 | } 44 | 45 | void ColorItem::enterEvent(QEvent *event) 46 | { 47 | _bMouseIn = true; 48 | update(); 49 | } 50 | 51 | void ColorItem::leaveEvent(QEvent *event) 52 | { 53 | _bMouseIn = false; 54 | update(); 55 | } 56 | 57 | void ColorItem::paintEvent(QPaintEvent *event) 58 | { 59 | QLabel::paintEvent(event); 60 | if (_bMouseIn) 61 | { 62 | QPainter painter(this); 63 | painter.setCompositionMode(QPainter::CompositionMode_Source); 64 | painter.setPen(QPen(Qt::white, 2)); 65 | painter.drawRect(1, 1, _item_length - 2, _item_length - 2); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ColorItem.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/ColorItem.h -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 ZyperChan 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 | -------------------------------------------------------------------------------- /LinePaint.cpp: -------------------------------------------------------------------------------- 1 | #include "LinePaint.h" 2 | 3 | LinePaint::LinePaint(const QLine &line, const QPen &pen) 4 | : QLine(line) 5 | { 6 | _pen = pen; 7 | } 8 | 9 | LinePaint::LinePaint(const QLine &line) 10 | : QLine(line) 11 | { 12 | 13 | } 14 | 15 | LinePaint::~LinePaint() 16 | { 17 | 18 | } 19 | 20 | void LinePaint::setPen(const QPen &pen) 21 | { 22 | _pen = pen; 23 | } 24 | 25 | const QPen& LinePaint::getPen() const 26 | { 27 | return _pen; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /LinePaint.h: -------------------------------------------------------------------------------- 1 | #ifndef LINEPAINT_H 2 | #define LINEPAINT_H 3 | 4 | #include 5 | #include 6 | 7 | class LinePaint : public QLine 8 | { 9 | public: 10 | LinePaint(const QLine &line, const QPen &pen); 11 | LinePaint(const QLine &line); 12 | ~LinePaint(); 13 | 14 | void setPen(const QPen &pen); 15 | const QPen& getPen() const; 16 | 17 | private: 18 | QPen _pen; 19 | }; 20 | 21 | #endif // LINEPAINT_H 22 | -------------------------------------------------------------------------------- /PointSizeWidget.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/PointSizeWidget.cpp -------------------------------------------------------------------------------- /PointSizeWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef POINTSIZEWIDGET_H 2 | #define POINTSIZEWIDGET_H 3 | 4 | #include "struct.h" 5 | #include 6 | 7 | #define LABELSIZE 2 * ITEM_LENGTH + 2 8 | 9 | class PointSizeWidget : public QLabel 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | PointSizeWidget(int point_size = 2, QWidget *parent = 0); 15 | ~PointSizeWidget(); 16 | 17 | void setPointSize(int point_size); 18 | int getPointSize() const; 19 | 20 | signals: 21 | void wheelscrolled(int point_size); 22 | 23 | protected: 24 | void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; 25 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 26 | 27 | private: 28 | int _point_size; 29 | QPoint _ptCenter; 30 | }; 31 | 32 | #endif // POINTSIZEWIDGET_H 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScreenShot(截屏贴图提高工作效率之神器) 2 | [![](https://img.shields.io/badge/Qt5-ScreenShot-brightgreen.svg)](https://www.qt.io) 3 | ![badge_platform](https://img.shields.io/badge/platform-Windows-brightgreen.svg) 4 | ![badge_lincense](https://img.shields.io/badge/license-MIT-blue.svg) 5 | ![windows](https://github.com/ZypherChan/ScreenShot/workflows/windows/badge.svg?branch=master) 6 | *** 7 | ## ScreenShot介绍 8 | - 🔧 基于Qt5开发的windows截图工具,主要是参照Snipaste来做的,可以说是阉割版的Snipaste 9 | - 🔧 同时也是桌面贴图工具,可贴图于桌面之上 10 | ## 目录 11 | - [主界面](#主界面) 12 | - [功能介绍](#功能介绍) 13 | - [亮点](#亮点) 14 | - [License](#license) 15 | ## 主界面 16 | ![](doc/main1.png) ![](doc/main2.png) 17 | ## 功能介绍 18 | ### 🔥查看图片 19 | 无边框桌面置顶显示,鼠标滚轮缩放图片 20 | ![](doc/f1.gif) 21 | ### 🔥截图功能 22 | 全局热键截图,截图后鼠标中键可直接贴图于桌面之上 23 | ![](doc/f2.gif) 24 | ### 🔥截图编辑功能 25 | 提供基本的画线面文字功能 26 | ![](doc/f3.gif) 27 | ### 🔥提供语言配置 28 | ![](doc/f5.gif) 29 | ## 亮点 30 | 当你没有多个屏幕显示的时候,可将需要的內容截屏贴图置于桌面一隅,方便快捷 31 | ![](doc/f4.gif) 32 | ## License 33 | 34 | [MIT © ZypherChan.](./LICENSE) 35 | -------------------------------------------------------------------------------- /RectPaint.cpp: -------------------------------------------------------------------------------- 1 | #include "RectPaint.h" 2 | 3 | RectPaint::RectPaint() 4 | { 5 | 6 | } 7 | 8 | RectPaint::RectPaint(const QPointF &topLeft, const QPointF &bottomRight, const QPen &pen, const QBrush &brush) 9 | :QRectF(topLeft, bottomRight), _pen(pen),_brush(brush) 10 | { 11 | 12 | } 13 | 14 | RectPaint::RectPaint(const QRectF &rect) 15 | : QRectF(rect) 16 | { 17 | 18 | } 19 | 20 | RectPaint::~RectPaint() 21 | { 22 | 23 | } 24 | 25 | void RectPaint::setPen(const QPen &pen) 26 | { 27 | _pen = pen; 28 | } 29 | 30 | const QPen& RectPaint::getPen() const 31 | { 32 | return _pen; 33 | } 34 | 35 | void RectPaint::setBrush(const QBrush &brush) 36 | { 37 | _brush = brush; 38 | } 39 | 40 | const QBrush& RectPaint::getBrush() const 41 | { 42 | return _brush; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /RectPaint.h: -------------------------------------------------------------------------------- 1 | #ifndef RECTPAINT_H 2 | #define RECTPAINT_H 3 | 4 | #include 5 | #include 6 | 7 | class RectPaint : public QRectF 8 | { 9 | public: 10 | RectPaint(); 11 | RectPaint(const QPointF &topLeft, const QPointF &bottomRight, const QPen &pen, const QBrush &brush); 12 | RectPaint(const QRectF &rect); 13 | ~RectPaint(); 14 | 15 | void setPen(const QPen &pen); 16 | const QPen& getPen() const; 17 | 18 | void setBrush(const QBrush &brush); 19 | const QBrush& getBrush() const; 20 | 21 | private: 22 | QPen _pen; 23 | QBrush _brush; 24 | }; 25 | 26 | #endif // RECTPAINT_H -------------------------------------------------------------------------------- /TextPaint.cpp: -------------------------------------------------------------------------------- 1 | #include "TextPaint.h" 2 | #include 3 | 4 | TextPaint::TextPaint(QWidget *parent) 5 | : QLineEdit(parent) 6 | { 7 | connect(this, SIGNAL(textChanged(QString)), this, SLOT(slt_autoResize())); 8 | connect(this, SIGNAL(editingFinished()), this, SLOT(slt_editEnd())); 9 | } 10 | 11 | TextPaint::~TextPaint() 12 | { 13 | 14 | } 15 | 16 | void TextPaint::slt_autoResize() 17 | { 18 | QFontMetrics fm(this->font()); 19 | this->setFixedWidth(fm.width(this->text()) + 6); 20 | this->setFixedHeight(fm.height() + 2); 21 | } 22 | 23 | void TextPaint::slt_editEnd() 24 | { 25 | this->setDisabled(true); 26 | } 27 | -------------------------------------------------------------------------------- /TextPaint.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTPAINT_H 2 | #define TEXTPAINT_H 3 | 4 | #include 5 | 6 | class TextPaint : public QLineEdit 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | TextPaint(QWidget *parent = Q_NULLPTR); 12 | ~TextPaint(); 13 | 14 | public slots: 15 | void slt_autoResize(); 16 | void slt_editEnd(); 17 | 18 | }; 19 | 20 | #endif // TEXTPAINT_H 21 | -------------------------------------------------------------------------------- /doc/f1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/f1.gif -------------------------------------------------------------------------------- /doc/f2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/f2.gif -------------------------------------------------------------------------------- /doc/f3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/f3.gif -------------------------------------------------------------------------------- /doc/f4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/f4.gif -------------------------------------------------------------------------------- /doc/f5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/f5.gif -------------------------------------------------------------------------------- /doc/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/main.png -------------------------------------------------------------------------------- /doc/main1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/main1.png -------------------------------------------------------------------------------- /doc/main2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/doc/main2.png -------------------------------------------------------------------------------- /image/BROOK.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/BROOK.ico -------------------------------------------------------------------------------- /image/LUFFY.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/LUFFY.ico -------------------------------------------------------------------------------- /image/ScreenShot20181209_203102.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/ScreenShot20181209_203102.jpg -------------------------------------------------------------------------------- /image/ZORO.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/ZORO.ico -------------------------------------------------------------------------------- /image/add.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/add.ico -------------------------------------------------------------------------------- /image/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/add.png -------------------------------------------------------------------------------- /image/brush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/brush.png -------------------------------------------------------------------------------- /image/comp.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/comp.ico -------------------------------------------------------------------------------- /image/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/copy.png -------------------------------------------------------------------------------- /image/drawellipse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/drawellipse.png -------------------------------------------------------------------------------- /image/drawline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/drawline.png -------------------------------------------------------------------------------- /image/drawrect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/drawrect.png -------------------------------------------------------------------------------- /image/drawtext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/drawtext.png -------------------------------------------------------------------------------- /image/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/file.png -------------------------------------------------------------------------------- /image/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/folder.png -------------------------------------------------------------------------------- /image/mail.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/mail.ico -------------------------------------------------------------------------------- /image/main.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/main.ico -------------------------------------------------------------------------------- /image/remove.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/remove.ico -------------------------------------------------------------------------------- /image/remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/remove.png -------------------------------------------------------------------------------- /image/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/save.png -------------------------------------------------------------------------------- /image/steam.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/steam.ico -------------------------------------------------------------------------------- /image/title.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/title.ico -------------------------------------------------------------------------------- /image/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/image/title.png -------------------------------------------------------------------------------- /imageview.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/imageview.cpp -------------------------------------------------------------------------------- /imageview.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEVIEW_H 2 | #define IMAGEVIEW_H 3 | 4 | #include 5 | #include "QImage" 6 | QT_BEGIN_NAMESPACE 7 | class QWheelEvent; 8 | QT_END_NAMESPACE 9 | 10 | 11 | class ImageView : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | ImageView(QWidget *parent = NULL); 17 | ~ImageView(); 18 | 19 | void setImage(const QString& imagepath); 20 | void setImage(const QPixmap& pixmap); 21 | void setImageGeometry(const QRect& rect); 22 | 23 | private: 24 | int m_current_scale; 25 | qreal m_zoomLevel; 26 | QPoint ptLast; 27 | bool m_bPressed; 28 | 29 | private: 30 | void initParam(); 31 | void initUI(); 32 | 33 | protected: 34 | void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE; 35 | void updateZoomLevel(); 36 | void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 37 | void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 38 | void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; 39 | void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; 40 | 41 | 42 | private: 43 | QPixmap m_pix; 44 | }; 45 | 46 | #endif // IMAGEVIEW_H 47 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "snappit.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | snappit w; 9 | w.switchLanguage("zh"); 10 | a.setQuitOnLastWindowClosed(false); 11 | 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /qtt.pri: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------- 2 | # This file is generated by the Qt Visual Studio Tools. 3 | # ------------------------------------------------------ 4 | 5 | # This is a reminder that you are using a generated .pro file. 6 | # Remove it when you are finished editing this file. 7 | message("You are running qmake on a generated .pro file. This may not work!") 8 | 9 | 10 | HEADERS += ./qxtglobal.h \ 11 | ./qxtglobalshortcut_p.h \ 12 | ./ColorItem.h \ 13 | ./LinePaint.h \ 14 | ./RectPaint.h \ 15 | ./PointSizeWidget.h \ 16 | ./qxtglobalshortcut.h \ 17 | ./TextPaint.h \ 18 | ./screenview.h \ 19 | ./imageview.h \ 20 | ./snappit.h \ 21 | ./struct.h 22 | SOURCES += ./ColorItem.cpp \ 23 | ./imageview.cpp \ 24 | ./LinePaint.cpp \ 25 | ./main.cpp \ 26 | ./PointSizeWidget.cpp \ 27 | ./qxtglobalshortcut.cpp \ 28 | ./qxtglobalshortcut_win.cpp \ 29 | ./RectPaint.cpp \ 30 | ./screenview.cpp \ 31 | ./snappit.cpp \ 32 | ./TextPaint.cpp 33 | FORMS += ./snappit.ui 34 | TRANSLATIONS += ./qtt_en.ts \ 35 | ./qtt_zh.ts 36 | RESOURCES += qtt.qrc 37 | -------------------------------------------------------------------------------- /qtt.pro: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------- 2 | # This file is generated by the Qt Visual Studio Tools. 3 | # ------------------------------------------------------ 4 | 5 | TEMPLATE = app 6 | TARGET = qtt 7 | DESTDIR = ../Win32/Release 8 | QT += core sql gui widgets 9 | CONFIG += release 10 | DEFINES += WIN64 QT_DLL QT_WIDGETS_LIB QT_SQL_LIB BUILD_QXT_GUI 11 | INCLUDEPATH += ./GeneratedFiles \ 12 | . \ 13 | ./GeneratedFiles/$(ConfigurationName) 14 | LIBS += -lkernel32 15 | LIBS += -luser32 16 | DEPENDPATH += . 17 | MOC_DIR += ./GeneratedFiles/$(ConfigurationName) 18 | OBJECTS_DIR += release 19 | UI_DIR += ./GeneratedFiles 20 | RCC_DIR += ./GeneratedFiles 21 | include(qtt.pri) 22 | TRANSLATIONS += qtt_en.ts \ 23 | qtt_zh.ts 24 | win32:RC_FILE = qtt.rc 25 | -------------------------------------------------------------------------------- /qtt.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | image/ZORO.ico 4 | image/LUFFY.ico 5 | image/BROOK.ico 6 | image/comp.ico 7 | image/mail.ico 8 | image/add.ico 9 | image/remove.ico 10 | image/title.ico 11 | image/add.png 12 | image/remove.png 13 | image/title.png 14 | image/file.png 15 | image/folder.png 16 | image/copy.png 17 | image/save.png 18 | image/drawline.png 19 | image/drawrect.png 20 | image/drawellipse.png 21 | image/drawtext.png 22 | image/brush.png 23 | image/main.ico 24 | translation/qtt_zh.qm 25 | translation/qtt_en.qm 26 | 27 | 28 | -------------------------------------------------------------------------------- /qtt.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/qtt.rc -------------------------------------------------------------------------------- /qxtglobal.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | ** Copyright (c) 2006 - 2011, the LibQxt project. 4 | ** See the Qxt AUTHORS file for a list of authors and copyright holders. 5 | ** All rights reserved. 6 | ** 7 | ** Redistribution and use in source and binary forms, with or without 8 | ** modification, are permitted provided that the following conditions are met: 9 | ** * Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** * Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** * Neither the name of the LibQxt project nor the 15 | ** names of its contributors may be used to endorse or promote products 16 | ** derived from this software without specific prior written permission. 17 | ** 18 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | ** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ** 29 | ** 30 | *****************************************************************************/ 31 | 32 | #ifndef QXTGLOBAL_H 33 | #define QXTGLOBAL_H 34 | 35 | #include 36 | 37 | #define QXT_VERSION 0x000700 38 | #define QXT_VERSION_STR "0.7.0" 39 | 40 | //--------------------------global macros------------------------------ 41 | 42 | #ifndef QXT_NO_MACROS 43 | 44 | #ifndef _countof 45 | #define _countof(x) (sizeof(x)/sizeof(*x)) 46 | #endif 47 | 48 | #endif // QXT_NO_MACROS 49 | 50 | //--------------------------export macros------------------------------ 51 | 52 | #define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE 53 | 54 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 55 | # if defined(BUILD_QXT_CORE) 56 | # define QXT_CORE_EXPORT Q_DECL_EXPORT 57 | # else 58 | # define QXT_CORE_EXPORT Q_DECL_IMPORT 59 | # endif 60 | #else 61 | # define QXT_CORE_EXPORT 62 | #endif // BUILD_QXT_CORE 63 | 64 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 65 | # if defined(BUILD_QXT_GUI) 66 | # define QXT_GUI_EXPORT Q_DECL_EXPORT 67 | # else 68 | # define QXT_GUI_EXPORT Q_DECL_IMPORT 69 | # endif 70 | #else 71 | # define QXT_GUI_EXPORT 72 | #endif // BUILD_QXT_GUI 73 | 74 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 75 | # if defined(BUILD_QXT_NETWORK) 76 | # define QXT_NETWORK_EXPORT Q_DECL_EXPORT 77 | # else 78 | # define QXT_NETWORK_EXPORT Q_DECL_IMPORT 79 | # endif 80 | #else 81 | # define QXT_NETWORK_EXPORT 82 | #endif // BUILD_QXT_NETWORK 83 | 84 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 85 | # if defined(BUILD_QXT_SQL) 86 | # define QXT_SQL_EXPORT Q_DECL_EXPORT 87 | # else 88 | # define QXT_SQL_EXPORT Q_DECL_IMPORT 89 | # endif 90 | #else 91 | # define QXT_SQL_EXPORT 92 | #endif // BUILD_QXT_SQL 93 | 94 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 95 | # if defined(BUILD_QXT_WEB) 96 | # define QXT_WEB_EXPORT Q_DECL_EXPORT 97 | # else 98 | # define QXT_WEB_EXPORT Q_DECL_IMPORT 99 | # endif 100 | #else 101 | # define QXT_WEB_EXPORT 102 | #endif // BUILD_QXT_WEB 103 | 104 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 105 | # if defined(BUILD_QXT_BERKELEY) 106 | # define QXT_BERKELEY_EXPORT Q_DECL_EXPORT 107 | # else 108 | # define QXT_BERKELEY_EXPORT Q_DECL_IMPORT 109 | # endif 110 | #else 111 | # define QXT_BERKELEY_EXPORT 112 | #endif // BUILD_QXT_BERKELEY 113 | 114 | #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN) 115 | # if defined(BUILD_QXT_ZEROCONF) 116 | # define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT 117 | # else 118 | # define QXT_ZEROCONF_EXPORT Q_DECL_IMPORT 119 | # endif 120 | #else 121 | # define QXT_ZEROCONF_EXPORT 122 | #endif // QXT_ZEROCONF_EXPORT 123 | 124 | #if defined(BUILD_QXT_CORE) || defined(BUILD_QXT_GUI) || defined(BUILD_QXT_SQL) || defined(BUILD_QXT_NETWORK) || defined(BUILD_QXT_WEB) || defined(BUILD_QXT_BERKELEY) || defined(BUILD_QXT_ZEROCONF) 125 | # define BUILD_QXT 126 | #endif 127 | 128 | QXT_CORE_EXPORT const char* qxtVersion(); 129 | 130 | #ifndef QT_BEGIN_NAMESPACE 131 | #define QT_BEGIN_NAMESPACE 132 | #endif 133 | 134 | #ifndef QT_END_NAMESPACE 135 | #define QT_END_NAMESPACE 136 | #endif 137 | 138 | #ifndef QT_FORWARD_DECLARE_CLASS 139 | #define QT_FORWARD_DECLARE_CLASS(Class) class Class; 140 | #endif 141 | 142 | /**************************************************************************** 143 | ** This file is derived from code bearing the following notice: 144 | ** The sole author of this file, Adam Higerd, has explicitly disclaimed all 145 | ** copyright interest and protection for the content within. This file has 146 | ** been placed in the public domain according to United States copyright 147 | ** statute and case law. In jurisdictions where this public domain dedication 148 | ** is not legally recognized, anyone who receives a copy of this file is 149 | ** permitted to use, modify, duplicate, and redistribute this file, in whole 150 | ** or in part, with no restrictions or conditions. In these jurisdictions, 151 | ** this file shall be copyright (C) 2006-2008 by Adam Higerd. 152 | ****************************************************************************/ 153 | 154 | #define QXT_DECLARE_PRIVATE(PUB) friend class PUB##Private; QxtPrivateInterface qxt_d; 155 | #define QXT_DECLARE_PUBLIC(PUB) friend class PUB; 156 | #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this); 157 | #define QXT_D(PUB) PUB##Private& d = qxt_d() 158 | #define QXT_P(PUB) PUB& p = qxt_p() 159 | 160 | template 161 | class QxtPrivate 162 | { 163 | public: 164 | virtual ~QxtPrivate() 165 | {} 166 | inline void QXT_setPublic(PUB* pub) 167 | { 168 | qxt_p_ptr = pub; 169 | } 170 | 171 | protected: 172 | inline PUB& qxt_p() 173 | { 174 | return *qxt_p_ptr; 175 | } 176 | inline const PUB& qxt_p() const 177 | { 178 | return *qxt_p_ptr; 179 | } 180 | inline PUB* qxt_ptr() 181 | { 182 | return qxt_p_ptr; 183 | } 184 | inline const PUB* qxt_ptr() const 185 | { 186 | return qxt_p_ptr; 187 | } 188 | 189 | private: 190 | PUB* qxt_p_ptr; 191 | }; 192 | 193 | template 194 | class QxtPrivateInterface 195 | { 196 | friend class QxtPrivate; 197 | public: 198 | QxtPrivateInterface() 199 | { 200 | pvt = new PVT; 201 | } 202 | ~QxtPrivateInterface() 203 | { 204 | delete pvt; 205 | } 206 | 207 | inline void setPublic(PUB* pub) 208 | { 209 | pvt->QXT_setPublic(pub); 210 | } 211 | inline PVT& operator()() 212 | { 213 | return *static_cast(pvt); 214 | } 215 | inline const PVT& operator()() const 216 | { 217 | return *static_cast(pvt); 218 | } 219 | inline PVT * operator->() 220 | { 221 | return static_cast(pvt); 222 | } 223 | inline const PVT * operator->() const 224 | { 225 | return static_cast(pvt); 226 | } 227 | private: 228 | QxtPrivateInterface(const QxtPrivateInterface&) { } 229 | QxtPrivateInterface& operator=(const QxtPrivateInterface&) { } 230 | QxtPrivate* pvt; 231 | }; 232 | 233 | #endif // QXT_GLOBAL 234 | -------------------------------------------------------------------------------- /qxtglobalshortcut.cpp: -------------------------------------------------------------------------------- 1 | #include "qxtglobalshortcut.h" 2 | /**************************************************************************** 3 | ** Copyright (c) 2006 - 2011, the LibQxt project. 4 | ** See the Qxt AUTHORS file for a list of authors and copyright holders. 5 | ** All rights reserved. 6 | ** 7 | ** Redistribution and use in source and binary forms, with or without 8 | ** modification, are permitted provided that the following conditions are met: 9 | ** * Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** * Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** * Neither the name of the LibQxt project nor the 15 | ** names of its contributors may be used to endorse or promote products 16 | ** derived from this software without specific prior written permission. 17 | ** 18 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | ** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ** 29 | ** 30 | *****************************************************************************/ 31 | 32 | #include "qxtglobalshortcut_p.h" 33 | #include 34 | #include 35 | 36 | #ifndef Q_OS_MAC 37 | int QxtGlobalShortcutPrivate::ref = 0; 38 | # if QT_VERSION < QT_VERSION_CHECK(5,0,0) 39 | QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0; 40 | # endif 41 | #endif // Q_OS_MAC 42 | QHash, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts; 43 | 44 | QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier) 45 | { 46 | #ifndef Q_OS_MAC 47 | if (ref == 0) { 48 | # if QT_VERSION < QT_VERSION_CHECK(5,0,0) 49 | prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter); 50 | # else 51 | QAbstractEventDispatcher::instance()->installNativeEventFilter(this); 52 | #endif 53 | } 54 | ++ref; 55 | #endif // Q_OS_MAC 56 | } 57 | 58 | QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate() 59 | { 60 | #ifndef Q_OS_MAC 61 | --ref; 62 | if (ref == 0) { 63 | QAbstractEventDispatcher *ed = QAbstractEventDispatcher::instance(); 64 | if (ed != 0) { 65 | # if QT_VERSION < QT_VERSION_CHECK(5,0,0) 66 | ed->setEventFilter(prevEventFilter); 67 | # else 68 | ed->removeNativeEventFilter(this); 69 | # endif 70 | } 71 | } 72 | #endif // Q_OS_MAC 73 | } 74 | 75 | bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) 76 | { 77 | Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; 78 | key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); 79 | mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods); 80 | const quint32 nativeKey = nativeKeycode(key); 81 | const quint32 nativeMods = nativeModifiers(mods); 82 | const bool res = registerShortcut(nativeKey, nativeMods); 83 | if (res) 84 | shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); 85 | else 86 | qWarning() << "QxtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString(); 87 | return res; 88 | } 89 | 90 | bool QxtGlobalShortcutPrivate::unsetShortcut() 91 | { 92 | bool res = false; 93 | const quint32 nativeKey = nativeKeycode(key); 94 | const quint32 nativeMods = nativeModifiers(mods); 95 | if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p()) 96 | res = unregisterShortcut(nativeKey, nativeMods); 97 | if (res) 98 | shortcuts.remove(qMakePair(nativeKey, nativeMods)); 99 | else 100 | qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); 101 | key = Qt::Key(0); 102 | mods = Qt::KeyboardModifiers(0); 103 | return res; 104 | } 105 | 106 | void QxtGlobalShortcutPrivate::activateShortcut(quint32 nativeKey, quint32 nativeMods) 107 | { 108 | QxtGlobalShortcut* shortcut = shortcuts.value(qMakePair(nativeKey, nativeMods)); 109 | if (shortcut && shortcut->isEnabled()) 110 | emit shortcut->activated(); 111 | } 112 | 113 | /*! 114 | \class QxtGlobalShortcut 115 | \inmodule QxtWidgets 116 | \brief The QxtGlobalShortcut class provides a global shortcut aka "hotkey". 117 | 118 | A global shortcut triggers even if the application is not active. This 119 | makes it easy to implement applications that react to certain shortcuts 120 | still if some other application is active or if the application is for 121 | example minimized to the system tray. 122 | 123 | Example usage: 124 | \code 125 | QxtGlobalShortcut* shortcut = new QxtGlobalShortcut(window); 126 | connect(shortcut, SIGNAL(activated()), window, SLOT(toggleVisibility())); 127 | shortcut->setShortcut(QKeySequence("Ctrl+Shift+F12")); 128 | \endcode 129 | 130 | \bold {Note:} Since Qxt 0.6 QxtGlobalShortcut no more requires QxtApplication. 131 | */ 132 | 133 | /*! 134 | \fn QxtGlobalShortcut::activated() 135 | 136 | This signal is emitted when the user types the shortcut's key sequence. 137 | 138 | \sa shortcut 139 | */ 140 | 141 | /*! 142 | Constructs a new QxtGlobalShortcut with \a parent. 143 | */ 144 | QxtGlobalShortcut::QxtGlobalShortcut(QObject* parent) 145 | : QObject(parent) 146 | { 147 | QXT_INIT_PRIVATE(QxtGlobalShortcut); 148 | } 149 | 150 | /*! 151 | Constructs a new QxtGlobalShortcut with \a shortcut and \a parent. 152 | */ 153 | QxtGlobalShortcut::QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent) 154 | : QObject(parent) 155 | { 156 | QXT_INIT_PRIVATE(QxtGlobalShortcut); 157 | setShortcut(shortcut); 158 | } 159 | 160 | /*! 161 | Destructs the QxtGlobalShortcut. 162 | */ 163 | QxtGlobalShortcut::~QxtGlobalShortcut() 164 | { 165 | if (qxt_d().key != 0) 166 | qxt_d().unsetShortcut(); 167 | } 168 | 169 | /*! 170 | \property QxtGlobalShortcut::shortcut 171 | \brief the shortcut key sequence 172 | 173 | \bold {Note:} Notice that corresponding key press and release events are not 174 | delivered for registered global shortcuts even if they are disabled. 175 | Also, comma separated key sequences are not supported. 176 | Only the first part is used: 177 | 178 | \code 179 | qxtShortcut->setShortcut(QKeySequence("Ctrl+Alt+A,Ctrl+Alt+B")); 180 | Q_ASSERT(qxtShortcut->shortcut() == QKeySequence("Ctrl+Alt+A")); 181 | \endcode 182 | */ 183 | QKeySequence QxtGlobalShortcut::shortcut() const 184 | { 185 | return QKeySequence(qxt_d().key | qxt_d().mods); 186 | } 187 | 188 | bool QxtGlobalShortcut::setShortcut(const QKeySequence& shortcut) 189 | { 190 | if (qxt_d().key != 0) 191 | qxt_d().unsetShortcut(); 192 | return qxt_d().setShortcut(shortcut); 193 | } 194 | 195 | /*! 196 | \property QxtGlobalShortcut::enabled 197 | \brief whether the shortcut is enabled 198 | 199 | A disabled shortcut does not get activated. 200 | 201 | The default value is \c true. 202 | 203 | \sa setDisabled() 204 | */ 205 | bool QxtGlobalShortcut::isEnabled() const 206 | { 207 | return qxt_d().enabled; 208 | } 209 | 210 | void QxtGlobalShortcut::setEnabled(bool enabled) 211 | { 212 | qxt_d().enabled = enabled; 213 | } 214 | 215 | /*! 216 | Sets the shortcut \a disabled. 217 | 218 | \sa enabled 219 | */ 220 | void QxtGlobalShortcut::setDisabled(bool disabled) 221 | { 222 | qxt_d().enabled = !disabled; 223 | } 224 | -------------------------------------------------------------------------------- /qxtglobalshortcut.h: -------------------------------------------------------------------------------- 1 | #ifndef QXTGLOBALSHORTCUT_H 2 | /**************************************************************************** 3 | ** Copyright (c) 2006 - 2011, the LibQxt project. 4 | ** See the Qxt AUTHORS file for a list of authors and copyright holders. 5 | ** All rights reserved. 6 | ** 7 | ** Redistribution and use in source and binary forms, with or without 8 | ** modification, are permitted provided that the following conditions are met: 9 | ** * Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** * Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** * Neither the name of the LibQxt project nor the 15 | ** names of its contributors may be used to endorse or promote products 16 | ** derived from this software without specific prior written permission. 17 | ** 18 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | ** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ** 29 | ** 30 | *****************************************************************************/ 31 | 32 | #define QXTGLOBALSHORTCUT_H 33 | 34 | #include "qxtglobal.h" 35 | #include 36 | #include 37 | class QxtGlobalShortcutPrivate; 38 | 39 | class QXT_GUI_EXPORT QxtGlobalShortcut : public QObject 40 | { 41 | Q_OBJECT 42 | QXT_DECLARE_PRIVATE(QxtGlobalShortcut) 43 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) 44 | Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut) 45 | 46 | public: 47 | explicit QxtGlobalShortcut(QObject* parent = 0); 48 | explicit QxtGlobalShortcut(const QKeySequence& shortcut, QObject* parent = 0); 49 | virtual ~QxtGlobalShortcut(); 50 | 51 | QKeySequence shortcut() const; 52 | bool setShortcut(const QKeySequence& shortcut); 53 | 54 | bool isEnabled() const; 55 | 56 | public Q_SLOTS: 57 | void setEnabled(bool enabled = true); 58 | void setDisabled(bool disabled = true); 59 | 60 | Q_SIGNALS: 61 | void activated(); 62 | }; 63 | 64 | #endif // QXTGLOBALSHORTCUT_H 65 | -------------------------------------------------------------------------------- /qxtglobalshortcut_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QXTGLOBALSHORTCUT_P_H 2 | /**************************************************************************** 3 | ** Copyright (c) 2006 - 2011, the LibQxt project. 4 | ** See the Qxt AUTHORS file for a list of authors and copyright holders. 5 | ** All rights reserved. 6 | ** 7 | ** Redistribution and use in source and binary forms, with or without 8 | ** modification, are permitted provided that the following conditions are met: 9 | ** * Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** * Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** * Neither the name of the LibQxt project nor the 15 | ** names of its contributors may be used to endorse or promote products 16 | ** derived from this software without specific prior written permission. 17 | ** 18 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | ** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ** 29 | ** 30 | *****************************************************************************/ 31 | 32 | #define QXTGLOBALSHORTCUT_P_H 33 | 34 | #include "qxtglobalshortcut.h" 35 | #include 36 | #include 37 | #include 38 | 39 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 40 | #include 41 | #endif 42 | 43 | 44 | class QxtGlobalShortcutPrivate : public QxtPrivate 45 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) && !defined(Q_OS_MAC) 46 | ,public QAbstractNativeEventFilter 47 | #endif 48 | { 49 | public: 50 | QXT_DECLARE_PUBLIC(QxtGlobalShortcut) 51 | QxtGlobalShortcutPrivate(); 52 | ~QxtGlobalShortcutPrivate(); 53 | 54 | bool enabled; 55 | Qt::Key key; 56 | Qt::KeyboardModifiers mods; 57 | 58 | bool setShortcut(const QKeySequence& shortcut); 59 | bool unsetShortcut(); 60 | 61 | static bool error; 62 | #ifndef Q_OS_MAC 63 | static int ref; 64 | #if QT_VERSION < QT_VERSION_CHECK(5,0,0) 65 | static QAbstractEventDispatcher::EventFilter prevEventFilter; 66 | static bool eventFilter(void* message); 67 | #else 68 | virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result); 69 | #endif // QT_VERSION < QT_VERSION_CHECK(5,0,0) 70 | #endif // Q_OS_MAC 71 | 72 | static void activateShortcut(quint32 nativeKey, quint32 nativeMods); 73 | 74 | private: 75 | static quint32 nativeKeycode(Qt::Key keycode); 76 | static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers); 77 | 78 | static bool registerShortcut(quint32 nativeKey, quint32 nativeMods); 79 | static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods); 80 | 81 | static QHash, QxtGlobalShortcut*> shortcuts; 82 | }; 83 | 84 | #endif // QXTGLOBALSHORTCUT_P_H 85 | -------------------------------------------------------------------------------- /qxtglobalshortcut_win.cpp: -------------------------------------------------------------------------------- 1 | #include "qxtglobalshortcut_p.h" 2 | /**************************************************************************** 3 | ** Copyright (c) 2006 - 2011, the LibQxt project. 4 | ** See the Qxt AUTHORS file for a list of authors and copyright holders. 5 | ** All rights reserved. 6 | ** 7 | ** Redistribution and use in source and binary forms, with or without 8 | ** modification, are permitted provided that the following conditions are met: 9 | ** * Redistributions of source code must retain the above copyright 10 | ** notice, this list of conditions and the following disclaimer. 11 | ** * Redistributions in binary form must reproduce the above copyright 12 | ** notice, this list of conditions and the following disclaimer in the 13 | ** documentation and/or other materials provided with the distribution. 14 | ** * Neither the name of the LibQxt project nor the 15 | ** names of its contributors may be used to endorse or promote products 16 | ** derived from this software without specific prior written permission. 17 | ** 18 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | ** DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 22 | ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ** 29 | ** 30 | *****************************************************************************/ 31 | 32 | #include 33 | 34 | 35 | #if QT_VERSION < QT_VERSION_CHECK(5,0,0) 36 | bool QxtGlobalShortcutPrivate::eventFilter(void* message) 37 | { 38 | #else 39 | bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType, 40 | void * message, long * result) 41 | { 42 | Q_UNUSED(eventType); 43 | Q_UNUSED(result); 44 | #endif 45 | MSG* msg = static_cast(message); 46 | if (msg->message == WM_HOTKEY) 47 | { 48 | const quint32 keycode = HIWORD(msg->lParam); 49 | const quint32 modifiers = LOWORD(msg->lParam); 50 | activateShortcut(keycode, modifiers); 51 | } 52 | 53 | #if QT_VERSION < QT_VERSION_CHECK(5,0,0) 54 | return prevEventFilter ? prevEventFilter(message) : false; 55 | #else 56 | return false; 57 | #endif 58 | } 59 | 60 | 61 | quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers) 62 | { 63 | // MOD_ALT, MOD_CONTROL, (MOD_KEYUP), MOD_SHIFT, MOD_WIN 64 | quint32 native = 0; 65 | if (modifiers & Qt::ShiftModifier) 66 | native |= MOD_SHIFT; 67 | if (modifiers & Qt::ControlModifier) 68 | native |= MOD_CONTROL; 69 | if (modifiers & Qt::AltModifier) 70 | native |= MOD_ALT; 71 | if (modifiers & Qt::MetaModifier) 72 | native |= MOD_WIN; 73 | // TODO: resolve these? 74 | //if (modifiers & Qt::KeypadModifier) 75 | //if (modifiers & Qt::GroupSwitchModifier) 76 | return native; 77 | } 78 | 79 | quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) 80 | { 81 | switch (key) 82 | { 83 | case Qt::Key_Escape: 84 | return VK_ESCAPE; 85 | case Qt::Key_Tab: 86 | case Qt::Key_Backtab: 87 | return VK_TAB; 88 | case Qt::Key_Backspace: 89 | return VK_BACK; 90 | case Qt::Key_Return: 91 | case Qt::Key_Enter: 92 | return VK_RETURN; 93 | case Qt::Key_Insert: 94 | return VK_INSERT; 95 | case Qt::Key_Delete: 96 | return VK_DELETE; 97 | case Qt::Key_Pause: 98 | return VK_PAUSE; 99 | case Qt::Key_Print: 100 | return VK_PRINT; 101 | case Qt::Key_Clear: 102 | return VK_CLEAR; 103 | case Qt::Key_Home: 104 | return VK_HOME; 105 | case Qt::Key_End: 106 | return VK_END; 107 | case Qt::Key_Left: 108 | return VK_LEFT; 109 | case Qt::Key_Up: 110 | return VK_UP; 111 | case Qt::Key_Right: 112 | return VK_RIGHT; 113 | case Qt::Key_Down: 114 | return VK_DOWN; 115 | case Qt::Key_PageUp: 116 | return VK_PRIOR; 117 | case Qt::Key_PageDown: 118 | return VK_NEXT; 119 | case Qt::Key_F1: 120 | return VK_F1; 121 | case Qt::Key_F2: 122 | return VK_F2; 123 | case Qt::Key_F3: 124 | return VK_F3; 125 | case Qt::Key_F4: 126 | return VK_F4; 127 | case Qt::Key_F5: 128 | return VK_F5; 129 | case Qt::Key_F6: 130 | return VK_F6; 131 | case Qt::Key_F7: 132 | return VK_F7; 133 | case Qt::Key_F8: 134 | return VK_F8; 135 | case Qt::Key_F9: 136 | return VK_F9; 137 | case Qt::Key_F10: 138 | return VK_F10; 139 | case Qt::Key_F11: 140 | return VK_F11; 141 | case Qt::Key_F12: 142 | return VK_F12; 143 | case Qt::Key_F13: 144 | return VK_F13; 145 | case Qt::Key_F14: 146 | return VK_F14; 147 | case Qt::Key_F15: 148 | return VK_F15; 149 | case Qt::Key_F16: 150 | return VK_F16; 151 | case Qt::Key_F17: 152 | return VK_F17; 153 | case Qt::Key_F18: 154 | return VK_F18; 155 | case Qt::Key_F19: 156 | return VK_F19; 157 | case Qt::Key_F20: 158 | return VK_F20; 159 | case Qt::Key_F21: 160 | return VK_F21; 161 | case Qt::Key_F22: 162 | return VK_F22; 163 | case Qt::Key_F23: 164 | return VK_F23; 165 | case Qt::Key_F24: 166 | return VK_F24; 167 | case Qt::Key_Space: 168 | return VK_SPACE; 169 | case Qt::Key_Asterisk: 170 | return VK_MULTIPLY; 171 | case Qt::Key_Plus: 172 | return VK_ADD; 173 | case Qt::Key_Comma: 174 | return VK_SEPARATOR; 175 | case Qt::Key_Minus: 176 | return VK_SUBTRACT; 177 | case Qt::Key_Slash: 178 | return VK_DIVIDE; 179 | case Qt::Key_MediaNext: 180 | return VK_MEDIA_NEXT_TRACK; 181 | case Qt::Key_MediaPrevious: 182 | return VK_MEDIA_PREV_TRACK; 183 | case Qt::Key_MediaPlay: 184 | return VK_MEDIA_PLAY_PAUSE; 185 | case Qt::Key_MediaStop: 186 | return VK_MEDIA_STOP; 187 | // couldn't find those in VK_* 188 | //case Qt::Key_MediaLast: 189 | //case Qt::Key_MediaRecord: 190 | case Qt::Key_VolumeDown: 191 | return VK_VOLUME_DOWN; 192 | case Qt::Key_VolumeUp: 193 | return VK_VOLUME_UP; 194 | case Qt::Key_VolumeMute: 195 | return VK_VOLUME_MUTE; 196 | 197 | // numbers 198 | case Qt::Key_0: 199 | case Qt::Key_1: 200 | case Qt::Key_2: 201 | case Qt::Key_3: 202 | case Qt::Key_4: 203 | case Qt::Key_5: 204 | case Qt::Key_6: 205 | case Qt::Key_7: 206 | case Qt::Key_8: 207 | case Qt::Key_9: 208 | return key; 209 | 210 | // letters 211 | case Qt::Key_A: 212 | case Qt::Key_B: 213 | case Qt::Key_C: 214 | case Qt::Key_D: 215 | case Qt::Key_E: 216 | case Qt::Key_F: 217 | case Qt::Key_G: 218 | case Qt::Key_H: 219 | case Qt::Key_I: 220 | case Qt::Key_J: 221 | case Qt::Key_K: 222 | case Qt::Key_L: 223 | case Qt::Key_M: 224 | case Qt::Key_N: 225 | case Qt::Key_O: 226 | case Qt::Key_P: 227 | case Qt::Key_Q: 228 | case Qt::Key_R: 229 | case Qt::Key_S: 230 | case Qt::Key_T: 231 | case Qt::Key_U: 232 | case Qt::Key_V: 233 | case Qt::Key_W: 234 | case Qt::Key_X: 235 | case Qt::Key_Y: 236 | case Qt::Key_Z: 237 | return key; 238 | 239 | default: 240 | return 0; 241 | } 242 | } 243 | 244 | bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) 245 | { 246 | return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey); 247 | } 248 | 249 | bool QxtGlobalShortcutPrivate::unregisterShortcut(quint32 nativeKey, quint32 nativeMods) 250 | { 251 | return UnregisterHotKey(0, nativeMods ^ nativeKey); 252 | } 253 | -------------------------------------------------------------------------------- /screenview.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/screenview.cpp -------------------------------------------------------------------------------- /screenview.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/screenview.h -------------------------------------------------------------------------------- /snappit.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/snappit.cpp -------------------------------------------------------------------------------- /snappit.h: -------------------------------------------------------------------------------- 1 | #ifndef SNAPPIT_H 2 | #define SNAPPIT_H 3 | 4 | #include 5 | #include "ui_snappit.h" 6 | #include "imageview.h" 7 | #include "screenview.h" 8 | #include 9 | #include "QMenu" 10 | 11 | class snappit : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | snappit(QWidget *parent = 0); 17 | ~snappit(); 18 | 19 | public: 20 | void openImage(); 21 | void screenShotCut(); 22 | void trayMenuTrigged(QAction* action); 23 | void trayActivated(QSystemTrayIcon::ActivationReason reason); 24 | void switchLanguage(const QString &text); 25 | 26 | private: 27 | void languageTranslate(); 28 | 29 | protected: 30 | void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE; 31 | void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; 32 | 33 | private: 34 | Ui::snappit ui; 35 | std::vector _arr_imgView; 36 | QString _file_path; 37 | QSystemTrayIcon *m_tray; 38 | QMenu *m_trayMenu; 39 | QAction *m_prefer; 40 | QAction *m_quit; 41 | QTranslator *m_translator; 42 | }; 43 | 44 | #endif // SNAPPIT_H 45 | -------------------------------------------------------------------------------- /snappit.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | snappit 4 | 5 | 6 | 7 | 0 8 | 0 9 | 350 10 | 360 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 350 22 | 360 23 | 24 | 25 | 26 | 27 | 350 28 | 360 29 | 30 | 31 | 32 | snappit 33 | 34 | 35 | 36 | 37 | 38 | 0 39 | 40 | 41 | 42 | 常规 43 | 44 | 45 | 46 | 47 | 10 48 | 10 49 | 75 50 | 23 51 | 52 | 53 | 54 | 打开 55 | 56 | 57 | 58 | 59 | 60 | 10 61 | 40 62 | 75 63 | 23 64 | 65 | 66 | 67 | 截屏 68 | 69 | 70 | 71 | 72 | 73 | 配置 74 | 75 | 76 | 77 | 78 | 10 79 | 20 80 | 131 81 | 22 82 | 83 | 84 | 85 | 86 | 87 | 88 | 语言: 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /struct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/struct.h -------------------------------------------------------------------------------- /third party/glog/include/glog/log_severity.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #ifndef BASE_LOG_SEVERITY_H__ 31 | #define BASE_LOG_SEVERITY_H__ 32 | 33 | // Annoying stuff for windows -- makes sure clients can import these functions 34 | #ifndef GOOGLE_GLOG_DLL_DECL 35 | # if defined(_WIN32) && !defined(__CYGWIN__) 36 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 37 | # else 38 | # define GOOGLE_GLOG_DLL_DECL 39 | # endif 40 | #endif 41 | 42 | // Variables of type LogSeverity are widely taken to lie in the range 43 | // [0, NUM_SEVERITIES-1]. Be careful to preserve this assumption if 44 | // you ever need to change their values or add a new severity. 45 | typedef int LogSeverity; 46 | 47 | const int GLOG_INFO = 0, GLOG_WARNING = 1, GLOG_ERROR = 2, GLOG_FATAL = 3, 48 | NUM_SEVERITIES = 4; 49 | #ifndef GLOG_NO_ABBREVIATED_SEVERITIES 50 | # ifdef ERROR 51 | # error ERROR macro is defined. Define GLOG_NO_ABBREVIATED_SEVERITIES before including logging.h. See the document for detail. 52 | # endif 53 | const int INFO = GLOG_INFO, WARNING = GLOG_WARNING, 54 | ERROR = GLOG_ERROR, FATAL = GLOG_FATAL; 55 | #endif 56 | 57 | // DFATAL is FATAL in debug mode, ERROR in normal mode 58 | #ifdef NDEBUG 59 | #define DFATAL_LEVEL ERROR 60 | #else 61 | #define DFATAL_LEVEL FATAL 62 | #endif 63 | 64 | extern GOOGLE_GLOG_DLL_DECL const char* const LogSeverityNames[NUM_SEVERITIES]; 65 | 66 | // NDEBUG usage helpers related to (RAW_)DCHECK: 67 | // 68 | // DEBUG_MODE is for small !NDEBUG uses like 69 | // if (DEBUG_MODE) foo.CheckThatFoo(); 70 | // instead of substantially more verbose 71 | // #ifndef NDEBUG 72 | // foo.CheckThatFoo(); 73 | // #endif 74 | // 75 | // IF_DEBUG_MODE is for small !NDEBUG uses like 76 | // IF_DEBUG_MODE( string error; ) 77 | // DCHECK(Foo(&error)) << error; 78 | // instead of substantially more verbose 79 | // #ifndef NDEBUG 80 | // string error; 81 | // DCHECK(Foo(&error)) << error; 82 | // #endif 83 | // 84 | #ifdef NDEBUG 85 | enum { DEBUG_MODE = 0 }; 86 | #define IF_DEBUG_MODE(x) 87 | #else 88 | enum { DEBUG_MODE = 1 }; 89 | #define IF_DEBUG_MODE(x) x 90 | #endif 91 | 92 | #endif // BASE_LOG_SEVERITY_H__ 93 | -------------------------------------------------------------------------------- /third party/glog/include/glog/vlog_is_on.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999, 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Ray Sidney and many others 31 | // 32 | // Defines the VLOG_IS_ON macro that controls the variable-verbosity 33 | // conditional logging. 34 | // 35 | // It's used by VLOG and VLOG_IF in logging.h 36 | // and by RAW_VLOG in raw_logging.h to trigger the logging. 37 | // 38 | // It can also be used directly e.g. like this: 39 | // if (VLOG_IS_ON(2)) { 40 | // // do some logging preparation and logging 41 | // // that can't be accomplished e.g. via just VLOG(2) << ...; 42 | // } 43 | // 44 | // The truth value that VLOG_IS_ON(level) returns is determined by 45 | // the three verbosity level flags: 46 | // --v= Gives the default maximal active V-logging level; 47 | // 0 is the default. 48 | // Normally positive values are used for V-logging levels. 49 | // --vmodule= Gives the per-module maximal V-logging levels to override 50 | // the value given by --v. 51 | // E.g. "my_module=2,foo*=3" would change the logging level 52 | // for all code in source files "my_module.*" and "foo*.*" 53 | // ("-inl" suffixes are also disregarded for this matching). 54 | // 55 | // SetVLOGLevel helper function is provided to do limited dynamic control over 56 | // V-logging by overriding the per-module settings given via --vmodule flag. 57 | // 58 | // CAVEAT: --vmodule functionality is not available in non gcc compilers. 59 | // 60 | 61 | #ifndef BASE_VLOG_IS_ON_H_ 62 | #define BASE_VLOG_IS_ON_H_ 63 | 64 | #include "glog/log_severity.h" 65 | 66 | // Annoying stuff for windows -- makes sure clients can import these functions 67 | #ifndef GOOGLE_GLOG_DLL_DECL 68 | # if defined(_WIN32) && !defined(__CYGWIN__) 69 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 70 | # else 71 | # define GOOGLE_GLOG_DLL_DECL 72 | # endif 73 | #endif 74 | 75 | #if defined(__GNUC__) 76 | // We emit an anonymous static int* variable at every VLOG_IS_ON(n) site. 77 | // (Normally) the first time every VLOG_IS_ON(n) site is hit, 78 | // we determine what variable will dynamically control logging at this site: 79 | // it's either FLAGS_v or an appropriate internal variable 80 | // matching the current source file that represents results of 81 | // parsing of --vmodule flag and/or SetVLOGLevel calls. 82 | #define VLOG_IS_ON(verboselevel) \ 83 | __extension__ \ 84 | ({ static google::int32* vlocal__ = &google::kLogSiteUninitialized; \ 85 | google::int32 verbose_level__ = (verboselevel); \ 86 | (*vlocal__ >= verbose_level__) && \ 87 | ((vlocal__ != &google::kLogSiteUninitialized) || \ 88 | (google::InitVLOG3__(&vlocal__, &FLAGS_v, \ 89 | __FILE__, verbose_level__))); }) 90 | #else 91 | // GNU extensions not available, so we do not support --vmodule. 92 | // Dynamic value of FLAGS_v always controls the logging level. 93 | #define VLOG_IS_ON(verboselevel) (FLAGS_v >= (verboselevel)) 94 | #endif 95 | 96 | // Set VLOG(_IS_ON) level for module_pattern to log_level. 97 | // This lets us dynamically control what is normally set by the --vmodule flag. 98 | // Returns the level that previously applied to module_pattern. 99 | // NOTE: To change the log level for VLOG(_IS_ON) sites 100 | // that have already executed after/during InitGoogleLogging, 101 | // one needs to supply the exact --vmodule pattern that applied to them. 102 | // (If no --vmodule pattern applied to them 103 | // the value of FLAGS_v will continue to control them.) 104 | extern GOOGLE_GLOG_DLL_DECL int SetVLOGLevel(const char* module_pattern, 105 | int log_level); 106 | 107 | // Various declarations needed for VLOG_IS_ON above: ========================= 108 | 109 | // Special value used to indicate that a VLOG_IS_ON site has not been 110 | // initialized. We make this a large value, so the common-case check 111 | // of "*vlocal__ >= verbose_level__" in VLOG_IS_ON definition 112 | // passes in such cases and InitVLOG3__ is then triggered. 113 | extern google::int32 kLogSiteUninitialized; 114 | 115 | // Helper routine which determines the logging info for a particalur VLOG site. 116 | // site_flag is the address of the site-local pointer to the controlling 117 | // verbosity level 118 | // site_default is the default to use for *site_flag 119 | // fname is the current source file name 120 | // verbose_level is the argument to VLOG_IS_ON 121 | // We will return the return value for VLOG_IS_ON 122 | // and if possible set *site_flag appropriately. 123 | extern GOOGLE_GLOG_DLL_DECL bool InitVLOG3__( 124 | google::int32** site_flag, 125 | google::int32* site_default, 126 | const char* fname, 127 | google::int32 verbose_level); 128 | 129 | #endif // BASE_VLOG_IS_ON_H_ 130 | -------------------------------------------------------------------------------- /third party/glog/include/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 1999, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Ray Sidney 31 | // 32 | // This file contains #include information about logging-related stuff. 33 | // Pretty much everybody needs to #include this file so that they can 34 | // log various happenings. 35 | // 36 | #ifndef _LOGGING_H_ 37 | #define _LOGGING_H_ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #if 0 47 | # include 48 | #endif 49 | #include 50 | 51 | #if defined(_MSC_VER) 52 | #define GLOG_MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \ 53 | __pragma(warning(disable:n)) 54 | #define GLOG_MSVC_POP_WARNING() __pragma(warning(pop)) 55 | #else 56 | #define GLOG_MSVC_PUSH_DISABLE_WARNING(n) 57 | #define GLOG_MSVC_POP_WARNING() 58 | #endif 59 | 60 | // Annoying stuff for windows -- makes sure clients can import these functions 61 | #ifndef GOOGLE_GLOG_DLL_DECL 62 | # if defined(_WIN32) && !defined(__CYGWIN__) 63 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 64 | # else 65 | # define GOOGLE_GLOG_DLL_DECL 66 | # endif 67 | #endif 68 | 69 | // We care a lot about number of bits things take up. Unfortunately, 70 | // systems define their bit-specific ints in a lot of different ways. 71 | // We use our own way, and have a typedef to get there. 72 | // Note: these commands below may look like "#if 1" or "#if 0", but 73 | // that's because they were constructed that way at ./configure time. 74 | // Look at logging.h.in to see how they're calculated (based on your config). 75 | #if 1 76 | #include // the normal place uint16_t is defined 77 | #endif 78 | #if 1 79 | #include // the normal place u_int16_t is defined 80 | #endif 81 | #if 1 82 | #include // a third place for uint16_t or u_int16_t 83 | #endif 84 | 85 | #if 0 86 | #include 87 | #endif 88 | 89 | namespace google { 90 | 91 | #if 1 // the C99 format 92 | typedef int32_t int32; 93 | typedef uint32_t uint32; 94 | typedef int64_t int64; 95 | typedef uint64_t uint64; 96 | #elif 0 // the BSD format 97 | typedef int32_t int32; 98 | typedef u_int32_t uint32; 99 | typedef int64_t int64; 100 | typedef u_int64_t uint64; 101 | #elif 1 // the windows (vc7) format 102 | typedef __int32 int32; 103 | typedef unsigned __int32 uint32; 104 | typedef __int64 int64; 105 | typedef unsigned __int64 uint64; 106 | #else 107 | #error Do not know how to define a 32-bit integer quantity on your system 108 | #endif 109 | 110 | } 111 | 112 | // The global value of GOOGLE_STRIP_LOG. All the messages logged to 113 | // LOG(XXX) with severity less than GOOGLE_STRIP_LOG will not be displayed. 114 | // If it can be determined at compile time that the message will not be 115 | // printed, the statement will be compiled out. 116 | // 117 | // Example: to strip out all INFO and WARNING messages, use the value 118 | // of 2 below. To make an exception for WARNING messages from a single 119 | // file, add "#define GOOGLE_STRIP_LOG 1" to that file _before_ including 120 | // base/logging.h 121 | #ifndef GOOGLE_STRIP_LOG 122 | #define GOOGLE_STRIP_LOG 0 123 | #endif 124 | 125 | // GCC can be told that a certain branch is not likely to be taken (for 126 | // instance, a CHECK failure), and use that information in static analysis. 127 | // Giving it this information can help it optimize for the common case in 128 | // the absence of better information (ie. -fprofile-arcs). 129 | // 130 | #ifndef GOOGLE_PREDICT_BRANCH_NOT_TAKEN 131 | #if 0 132 | #define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) (__builtin_expect(x, 0)) 133 | #else 134 | #define GOOGLE_PREDICT_BRANCH_NOT_TAKEN(x) x 135 | #endif 136 | #endif 137 | 138 | #ifndef GOOGLE_PREDICT_FALSE 139 | #if 0 140 | #define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0)) 141 | #else 142 | #define GOOGLE_PREDICT_FALSE(x) x 143 | #endif 144 | #endif 145 | 146 | #ifndef GOOGLE_PREDICT_TRUE 147 | #if 0 148 | #define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) 149 | #else 150 | #define GOOGLE_PREDICT_TRUE(x) x 151 | #endif 152 | #endif 153 | 154 | 155 | // Make a bunch of macros for logging. The way to log things is to stream 156 | // things to LOG(). E.g., 157 | // 158 | // LOG(INFO) << "Found " << num_cookies << " cookies"; 159 | // 160 | // You can capture log messages in a string, rather than reporting them 161 | // immediately: 162 | // 163 | // vector errors; 164 | // LOG_STRING(ERROR, &errors) << "Couldn't parse cookie #" << cookie_num; 165 | // 166 | // This pushes back the new error onto 'errors'; if given a NULL pointer, 167 | // it reports the error via LOG(ERROR). 168 | // 169 | // You can also do conditional logging: 170 | // 171 | // LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; 172 | // 173 | // You can also do occasional logging (log every n'th occurrence of an 174 | // event): 175 | // 176 | // LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; 177 | // 178 | // The above will cause log messages to be output on the 1st, 11th, 21st, ... 179 | // times it is executed. Note that the special google::COUNTER value is used 180 | // to identify which repetition is happening. 181 | // 182 | // You can also do occasional conditional logging (log every n'th 183 | // occurrence of an event, when condition is satisfied): 184 | // 185 | // LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER 186 | // << "th big cookie"; 187 | // 188 | // You can log messages the first N times your code executes a line. E.g. 189 | // 190 | // LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie"; 191 | // 192 | // Outputs log messages for the first 20 times it is executed. 193 | // 194 | // Analogous SYSLOG, SYSLOG_IF, and SYSLOG_EVERY_N macros are available. 195 | // These log to syslog as well as to the normal logs. If you use these at 196 | // all, you need to be aware that syslog can drastically reduce performance, 197 | // especially if it is configured for remote logging! Don't use these 198 | // unless you fully understand this and have a concrete need to use them. 199 | // Even then, try to minimize your use of them. 200 | // 201 | // There are also "debug mode" logging macros like the ones above: 202 | // 203 | // DLOG(INFO) << "Found cookies"; 204 | // 205 | // DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies"; 206 | // 207 | // DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie"; 208 | // 209 | // All "debug mode" logging is compiled away to nothing for non-debug mode 210 | // compiles. 211 | // 212 | // We also have 213 | // 214 | // LOG_ASSERT(assertion); 215 | // DLOG_ASSERT(assertion); 216 | // 217 | // which is syntactic sugar for {,D}LOG_IF(FATAL, assert fails) << assertion; 218 | // 219 | // There are "verbose level" logging macros. They look like 220 | // 221 | // VLOG(1) << "I'm printed when you run the program with --v=1 or more"; 222 | // VLOG(2) << "I'm printed when you run the program with --v=2 or more"; 223 | // 224 | // These always log at the INFO log level (when they log at all). 225 | // The verbose logging can also be turned on module-by-module. For instance, 226 | // --vmodule=mapreduce=2,file=1,gfs*=3 --v=0 227 | // will cause: 228 | // a. VLOG(2) and lower messages to be printed from mapreduce.{h,cc} 229 | // b. VLOG(1) and lower messages to be printed from file.{h,cc} 230 | // c. VLOG(3) and lower messages to be printed from files prefixed with "gfs" 231 | // d. VLOG(0) and lower messages to be printed from elsewhere 232 | // 233 | // The wildcarding functionality shown by (c) supports both '*' (match 234 | // 0 or more characters) and '?' (match any single character) wildcards. 235 | // 236 | // There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as 237 | // 238 | // if (VLOG_IS_ON(2)) { 239 | // // do some logging preparation and logging 240 | // // that can't be accomplished with just VLOG(2) << ...; 241 | // } 242 | // 243 | // There are also VLOG_IF, VLOG_EVERY_N and VLOG_IF_EVERY_N "verbose level" 244 | // condition macros for sample cases, when some extra computation and 245 | // preparation for logs is not needed. 246 | // VLOG_IF(1, (size > 1024)) 247 | // << "I'm printed when size is more than 1024 and when you run the " 248 | // "program with --v=1 or more"; 249 | // VLOG_EVERY_N(1, 10) 250 | // << "I'm printed every 10th occurrence, and when you run the program " 251 | // "with --v=1 or more. Present occurence is " << google::COUNTER; 252 | // VLOG_IF_EVERY_N(1, (size > 1024), 10) 253 | // << "I'm printed on every 10th occurence of case when size is more " 254 | // " than 1024, when you run the program with --v=1 or more. "; 255 | // "Present occurence is " << google::COUNTER; 256 | // 257 | // The supported severity levels for macros that allow you to specify one 258 | // are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL. 259 | // Note that messages of a given severity are logged not only in the 260 | // logfile for that severity, but also in all logfiles of lower severity. 261 | // E.g., a message of severity FATAL will be logged to the logfiles of 262 | // severity FATAL, ERROR, WARNING, and INFO. 263 | // 264 | // There is also the special severity of DFATAL, which logs FATAL in 265 | // debug mode, ERROR in normal mode. 266 | // 267 | // Very important: logging a message at the FATAL severity level causes 268 | // the program to terminate (after the message is logged). 269 | // 270 | // Unless otherwise specified, logs will be written to the filename 271 | // "...log..", followed 272 | // by the date, time, and pid (you can't prevent the date, time, and pid 273 | // from being in the filename). 274 | // 275 | // The logging code takes two flags: 276 | // --v=# set the verbose level 277 | // --logtostderr log all the messages to stderr instead of to logfiles 278 | 279 | // LOG LINE PREFIX FORMAT 280 | // 281 | // Log lines have this form: 282 | // 283 | // Lmmdd hh:mm:ss.uuuuuu threadid file:line] msg... 284 | // 285 | // where the fields are defined as follows: 286 | // 287 | // L A single character, representing the log level 288 | // (eg 'I' for INFO) 289 | // mm The month (zero padded; ie May is '05') 290 | // dd The day (zero padded) 291 | // hh:mm:ss.uuuuuu Time in hours, minutes and fractional seconds 292 | // threadid The space-padded thread ID as returned by GetTID() 293 | // (this matches the PID on Linux) 294 | // file The file name 295 | // line The line number 296 | // msg The user-supplied message 297 | // 298 | // Example: 299 | // 300 | // I1103 11:57:31.739339 24395 google.cc:2341] Command line: ./some_prog 301 | // I1103 11:57:31.739403 24395 google.cc:2342] Process id 24395 302 | // 303 | // NOTE: although the microseconds are useful for comparing events on 304 | // a single machine, clocks on different machines may not be well 305 | // synchronized. Hence, use caution when comparing the low bits of 306 | // timestamps from different machines. 307 | 308 | #ifndef DECLARE_VARIABLE 309 | #define MUST_UNDEF_GFLAGS_DECLARE_MACROS 310 | #define DECLARE_VARIABLE(type, shorttype, name, tn) \ 311 | namespace fL##shorttype { \ 312 | extern GOOGLE_GLOG_DLL_DECL type FLAGS_##name; \ 313 | } \ 314 | using fL##shorttype::FLAGS_##name 315 | 316 | // bool specialization 317 | #define DECLARE_bool(name) \ 318 | DECLARE_VARIABLE(bool, B, name, bool) 319 | 320 | // int32 specialization 321 | #define DECLARE_int32(name) \ 322 | DECLARE_VARIABLE(google::int32, I, name, int32) 323 | 324 | // Special case for string, because we have to specify the namespace 325 | // std::string, which doesn't play nicely with our FLAG__namespace hackery. 326 | #define DECLARE_string(name) \ 327 | namespace fLS { \ 328 | extern GOOGLE_GLOG_DLL_DECL std::string& FLAGS_##name; \ 329 | } \ 330 | using fLS::FLAGS_##name 331 | #endif 332 | 333 | // Set whether log messages go to stderr instead of logfiles 334 | DECLARE_bool(logtostderr); 335 | 336 | // Set whether log messages go to stderr in addition to logfiles. 337 | DECLARE_bool(alsologtostderr); 338 | 339 | // Set color messages logged to stderr (if supported by terminal). 340 | DECLARE_bool(colorlogtostderr); 341 | 342 | // Log messages at a level >= this flag are automatically sent to 343 | // stderr in addition to log files. 344 | DECLARE_int32(stderrthreshold); 345 | 346 | // Set whether the log prefix should be prepended to each line of output. 347 | DECLARE_bool(log_prefix); 348 | 349 | // Log messages at a level <= this flag are buffered. 350 | // Log messages at a higher level are flushed immediately. 351 | DECLARE_int32(logbuflevel); 352 | 353 | // Sets the maximum number of seconds which logs may be buffered for. 354 | DECLARE_int32(logbufsecs); 355 | 356 | // Log suppression level: messages logged at a lower level than this 357 | // are suppressed. 358 | DECLARE_int32(minloglevel); 359 | 360 | // If specified, logfiles are written into this directory instead of the 361 | // default logging directory. 362 | DECLARE_string(log_dir); 363 | 364 | // Set the log file mode. 365 | DECLARE_int32(logfile_mode); 366 | 367 | // Sets the path of the directory into which to put additional links 368 | // to the log files. 369 | DECLARE_string(log_link); 370 | 371 | DECLARE_int32(v); // in vlog_is_on.cc 372 | 373 | // Sets the maximum log file size (in MB). 374 | DECLARE_int32(max_log_size); 375 | 376 | // Sets whether to avoid logging to the disk if the disk is full. 377 | DECLARE_bool(stop_logging_if_full_disk); 378 | 379 | #ifdef MUST_UNDEF_GFLAGS_DECLARE_MACROS 380 | #undef MUST_UNDEF_GFLAGS_DECLARE_MACROS 381 | #undef DECLARE_VARIABLE 382 | #undef DECLARE_bool 383 | #undef DECLARE_int32 384 | #undef DECLARE_string 385 | #endif 386 | 387 | // Log messages below the GOOGLE_STRIP_LOG level will be compiled away for 388 | // security reasons. See LOG(severtiy) below. 389 | 390 | // A few definitions of macros that don't generate much code. Since 391 | // LOG(INFO) and its ilk are used all over our code, it's 392 | // better to have compact code for these operations. 393 | 394 | #if GOOGLE_STRIP_LOG == 0 395 | #define COMPACT_GOOGLE_LOG_INFO google::LogMessage( \ 396 | __FILE__, __LINE__) 397 | #define LOG_TO_STRING_INFO(message) google::LogMessage( \ 398 | __FILE__, __LINE__, google::GLOG_INFO, message) 399 | #else 400 | #define COMPACT_GOOGLE_LOG_INFO google::NullStream() 401 | #define LOG_TO_STRING_INFO(message) google::NullStream() 402 | #endif 403 | 404 | #if GOOGLE_STRIP_LOG <= 1 405 | #define COMPACT_GOOGLE_LOG_WARNING google::LogMessage( \ 406 | __FILE__, __LINE__, google::GLOG_WARNING) 407 | #define LOG_TO_STRING_WARNING(message) google::LogMessage( \ 408 | __FILE__, __LINE__, google::GLOG_WARNING, message) 409 | #else 410 | #define COMPACT_GOOGLE_LOG_WARNING google::NullStream() 411 | #define LOG_TO_STRING_WARNING(message) google::NullStream() 412 | #endif 413 | 414 | #if GOOGLE_STRIP_LOG <= 2 415 | #define COMPACT_GOOGLE_LOG_ERROR google::LogMessage( \ 416 | __FILE__, __LINE__, google::GLOG_ERROR) 417 | #define LOG_TO_STRING_ERROR(message) google::LogMessage( \ 418 | __FILE__, __LINE__, google::GLOG_ERROR, message) 419 | #else 420 | #define COMPACT_GOOGLE_LOG_ERROR google::NullStream() 421 | #define LOG_TO_STRING_ERROR(message) google::NullStream() 422 | #endif 423 | 424 | #if GOOGLE_STRIP_LOG <= 3 425 | #define COMPACT_GOOGLE_LOG_FATAL google::LogMessageFatal( \ 426 | __FILE__, __LINE__) 427 | #define LOG_TO_STRING_FATAL(message) google::LogMessage( \ 428 | __FILE__, __LINE__, google::GLOG_FATAL, message) 429 | #else 430 | #define COMPACT_GOOGLE_LOG_FATAL google::NullStreamFatal() 431 | #define LOG_TO_STRING_FATAL(message) google::NullStreamFatal() 432 | #endif 433 | 434 | #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 435 | #define DCHECK_IS_ON() 0 436 | #else 437 | #define DCHECK_IS_ON() 1 438 | #endif 439 | 440 | // For DFATAL, we want to use LogMessage (as opposed to 441 | // LogMessageFatal), to be consistent with the original behavior. 442 | #if !DCHECK_IS_ON() 443 | #define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR 444 | #elif GOOGLE_STRIP_LOG <= 3 445 | #define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \ 446 | __FILE__, __LINE__, google::GLOG_FATAL) 447 | #else 448 | #define COMPACT_GOOGLE_LOG_DFATAL google::NullStreamFatal() 449 | #endif 450 | 451 | #define GOOGLE_LOG_INFO(counter) google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, &google::LogMessage::SendToLog) 452 | #define SYSLOG_INFO(counter) \ 453 | google::LogMessage(__FILE__, __LINE__, google::GLOG_INFO, counter, \ 454 | &google::LogMessage::SendToSyslogAndLog) 455 | #define GOOGLE_LOG_WARNING(counter) \ 456 | google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ 457 | &google::LogMessage::SendToLog) 458 | #define SYSLOG_WARNING(counter) \ 459 | google::LogMessage(__FILE__, __LINE__, google::GLOG_WARNING, counter, \ 460 | &google::LogMessage::SendToSyslogAndLog) 461 | #define GOOGLE_LOG_ERROR(counter) \ 462 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ 463 | &google::LogMessage::SendToLog) 464 | #define SYSLOG_ERROR(counter) \ 465 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, counter, \ 466 | &google::LogMessage::SendToSyslogAndLog) 467 | #define GOOGLE_LOG_FATAL(counter) \ 468 | google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ 469 | &google::LogMessage::SendToLog) 470 | #define SYSLOG_FATAL(counter) \ 471 | google::LogMessage(__FILE__, __LINE__, google::GLOG_FATAL, counter, \ 472 | &google::LogMessage::SendToSyslogAndLog) 473 | #define GOOGLE_LOG_DFATAL(counter) \ 474 | google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ 475 | &google::LogMessage::SendToLog) 476 | #define SYSLOG_DFATAL(counter) \ 477 | google::LogMessage(__FILE__, __LINE__, google::DFATAL_LEVEL, counter, \ 478 | &google::LogMessage::SendToSyslogAndLog) 479 | 480 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) || defined(__CYGWIN32__) 481 | // A very useful logging macro to log windows errors: 482 | #define LOG_SYSRESULT(result) \ 483 | if (FAILED(HRESULT_FROM_WIN32(result))) { \ 484 | LPSTR message = NULL; \ 485 | LPSTR msg = reinterpret_cast(&message); \ 486 | DWORD message_length = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | \ 487 | FORMAT_MESSAGE_FROM_SYSTEM, \ 488 | 0, result, 0, msg, 100, NULL); \ 489 | if (message_length > 0) { \ 490 | google::LogMessage(__FILE__, __LINE__, google::GLOG_ERROR, 0, \ 491 | &google::LogMessage::SendToLog).stream() \ 492 | << reinterpret_cast(message); \ 493 | LocalFree(message); \ 494 | } \ 495 | } 496 | #endif 497 | 498 | // We use the preprocessor's merging operator, "##", so that, e.g., 499 | // LOG(INFO) becomes the token GOOGLE_LOG_INFO. There's some funny 500 | // subtle difference between ostream member streaming functions (e.g., 501 | // ostream::operator<<(int) and ostream non-member streaming functions 502 | // (e.g., ::operator<<(ostream&, string&): it turns out that it's 503 | // impossible to stream something like a string directly to an unnamed 504 | // ostream. We employ a neat hack by calling the stream() member 505 | // function of LogMessage which seems to avoid the problem. 506 | #define LOG(severity) COMPACT_GOOGLE_LOG_ ## severity.stream() 507 | #define SYSLOG(severity) SYSLOG_ ## severity(0).stream() 508 | 509 | namespace google { 510 | 511 | // They need the definitions of integer types. 512 | #include "glog/log_severity.h" 513 | #include "glog/vlog_is_on.h" 514 | 515 | // Initialize google's logging library. You will see the program name 516 | // specified by argv0 in log outputs. 517 | GOOGLE_GLOG_DLL_DECL void InitGoogleLogging(const char* argv0); 518 | 519 | // Shutdown google's logging library. 520 | GOOGLE_GLOG_DLL_DECL void ShutdownGoogleLogging(); 521 | 522 | // Install a function which will be called after LOG(FATAL). 523 | GOOGLE_GLOG_DLL_DECL void InstallFailureFunction(void (*fail_func)()); 524 | 525 | class LogSink; // defined below 526 | 527 | // If a non-NULL sink pointer is given, we push this message to that sink. 528 | // For LOG_TO_SINK we then do normal LOG(severity) logging as well. 529 | // This is useful for capturing messages and passing/storing them 530 | // somewhere more specific than the global log of the process. 531 | // Argument types: 532 | // LogSink* sink; 533 | // LogSeverity severity; 534 | // The cast is to disambiguate NULL arguments. 535 | #define LOG_TO_SINK(sink, severity) \ 536 | google::LogMessage( \ 537 | __FILE__, __LINE__, \ 538 | google::GLOG_ ## severity, \ 539 | static_cast(sink), true).stream() 540 | #define LOG_TO_SINK_BUT_NOT_TO_LOGFILE(sink, severity) \ 541 | google::LogMessage( \ 542 | __FILE__, __LINE__, \ 543 | google::GLOG_ ## severity, \ 544 | static_cast(sink), false).stream() 545 | 546 | // If a non-NULL string pointer is given, we write this message to that string. 547 | // We then do normal LOG(severity) logging as well. 548 | // This is useful for capturing messages and storing them somewhere more 549 | // specific than the global log of the process. 550 | // Argument types: 551 | // string* message; 552 | // LogSeverity severity; 553 | // The cast is to disambiguate NULL arguments. 554 | // NOTE: LOG(severity) expands to LogMessage().stream() for the specified 555 | // severity. 556 | #define LOG_TO_STRING(severity, message) \ 557 | LOG_TO_STRING_##severity(static_cast(message)).stream() 558 | 559 | // If a non-NULL pointer is given, we push the message onto the end 560 | // of a vector of strings; otherwise, we report it with LOG(severity). 561 | // This is handy for capturing messages and perhaps passing them back 562 | // to the caller, rather than reporting them immediately. 563 | // Argument types: 564 | // LogSeverity severity; 565 | // vector *outvec; 566 | // The cast is to disambiguate NULL arguments. 567 | #define LOG_STRING(severity, outvec) \ 568 | LOG_TO_STRING_##severity(static_cast*>(outvec)).stream() 569 | 570 | #define LOG_IF(severity, condition) \ 571 | !(condition) ? (void) 0 : google::LogMessageVoidify() & LOG(severity) 572 | #define SYSLOG_IF(severity, condition) \ 573 | !(condition) ? (void) 0 : google::LogMessageVoidify() & SYSLOG(severity) 574 | 575 | #define LOG_ASSERT(condition) \ 576 | LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition 577 | #define SYSLOG_ASSERT(condition) \ 578 | SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition 579 | 580 | // CHECK dies with a fatal error if condition is not true. It is *not* 581 | // controlled by DCHECK_IS_ON(), so the check will be executed regardless of 582 | // compilation mode. Therefore, it is safe to do things like: 583 | // CHECK(fp->Write(x) == 4) 584 | #define CHECK(condition) \ 585 | LOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \ 586 | << "Check failed: " #condition " " 587 | 588 | // A container for a string pointer which can be evaluated to a bool - 589 | // true iff the pointer is NULL. 590 | struct CheckOpString { 591 | CheckOpString(std::string* str) : str_(str) { } 592 | // No destructor: if str_ is non-NULL, we're about to LOG(FATAL), 593 | // so there's no point in cleaning up str_. 594 | operator bool() const { 595 | return GOOGLE_PREDICT_BRANCH_NOT_TAKEN(str_ != NULL); 596 | } 597 | std::string* str_; 598 | }; 599 | 600 | // Function is overloaded for integral types to allow static const 601 | // integrals declared in classes and not defined to be used as arguments to 602 | // CHECK* macros. It's not encouraged though. 603 | template 604 | inline const T& GetReferenceableValue(const T& t) { return t; } 605 | inline char GetReferenceableValue(char t) { return t; } 606 | inline unsigned char GetReferenceableValue(unsigned char t) { return t; } 607 | inline signed char GetReferenceableValue(signed char t) { return t; } 608 | inline short GetReferenceableValue(short t) { return t; } 609 | inline unsigned short GetReferenceableValue(unsigned short t) { return t; } 610 | inline int GetReferenceableValue(int t) { return t; } 611 | inline unsigned int GetReferenceableValue(unsigned int t) { return t; } 612 | inline long GetReferenceableValue(long t) { return t; } 613 | inline unsigned long GetReferenceableValue(unsigned long t) { return t; } 614 | inline long long GetReferenceableValue(long long t) { return t; } 615 | inline unsigned long long GetReferenceableValue(unsigned long long t) { 616 | return t; 617 | } 618 | 619 | // This is a dummy class to define the following operator. 620 | struct DummyClassToDefineOperator {}; 621 | 622 | } 623 | 624 | // Define global operator<< to declare using ::operator<<. 625 | // This declaration will allow use to use CHECK macros for user 626 | // defined classes which have operator<< (e.g., stl_logging.h). 627 | inline std::ostream& operator<<( 628 | std::ostream& out, const google::DummyClassToDefineOperator&) { 629 | return out; 630 | } 631 | 632 | namespace google { 633 | 634 | // This formats a value for a failing CHECK_XX statement. Ordinarily, 635 | // it uses the definition for operator<<, with a few special cases below. 636 | template 637 | inline void MakeCheckOpValueString(std::ostream* os, const T& v) { 638 | (*os) << v; 639 | } 640 | 641 | // Overrides for char types provide readable values for unprintable 642 | // characters. 643 | template <> GOOGLE_GLOG_DLL_DECL 644 | void MakeCheckOpValueString(std::ostream* os, const char& v); 645 | template <> GOOGLE_GLOG_DLL_DECL 646 | void MakeCheckOpValueString(std::ostream* os, const signed char& v); 647 | template <> GOOGLE_GLOG_DLL_DECL 648 | void MakeCheckOpValueString(std::ostream* os, const unsigned char& v); 649 | 650 | // Build the error message string. Specify no inlining for code size. 651 | template 652 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) 653 | ; 654 | 655 | namespace base { 656 | namespace internal { 657 | 658 | // If "s" is less than base_logging::INFO, returns base_logging::INFO. 659 | // If "s" is greater than base_logging::FATAL, returns 660 | // base_logging::ERROR. Otherwise, returns "s". 661 | LogSeverity NormalizeSeverity(LogSeverity s); 662 | 663 | } // namespace internal 664 | 665 | // A helper class for formatting "expr (V1 vs. V2)" in a CHECK_XX 666 | // statement. See MakeCheckOpString for sample usage. Other 667 | // approaches were considered: use of a template method (e.g., 668 | // base::BuildCheckOpString(exprtext, base::Print, &v1, 669 | // base::Print, &v2), however this approach has complications 670 | // related to volatile arguments and function-pointer arguments). 671 | class GOOGLE_GLOG_DLL_DECL CheckOpMessageBuilder { 672 | public: 673 | // Inserts "exprtext" and " (" to the stream. 674 | explicit CheckOpMessageBuilder(const char *exprtext); 675 | // Deletes "stream_". 676 | ~CheckOpMessageBuilder(); 677 | // For inserting the first variable. 678 | std::ostream* ForVar1() { return stream_; } 679 | // For inserting the second variable (adds an intermediate " vs. "). 680 | std::ostream* ForVar2(); 681 | // Get the result (inserts the closing ")"). 682 | std::string* NewString(); 683 | 684 | private: 685 | std::ostringstream *stream_; 686 | }; 687 | 688 | } // namespace base 689 | 690 | template 691 | std::string* MakeCheckOpString(const T1& v1, const T2& v2, const char* exprtext) { 692 | base::CheckOpMessageBuilder comb(exprtext); 693 | MakeCheckOpValueString(comb.ForVar1(), v1); 694 | MakeCheckOpValueString(comb.ForVar2(), v2); 695 | return comb.NewString(); 696 | } 697 | 698 | // Helper functions for CHECK_OP macro. 699 | // The (int, int) specialization works around the issue that the compiler 700 | // will not instantiate the template version of the function on values of 701 | // unnamed enum type - see comment below. 702 | #define DEFINE_CHECK_OP_IMPL(name, op) \ 703 | template \ 704 | inline std::string* name##Impl(const T1& v1, const T2& v2, \ 705 | const char* exprtext) { \ 706 | if (GOOGLE_PREDICT_TRUE(v1 op v2)) return NULL; \ 707 | else return MakeCheckOpString(v1, v2, exprtext); \ 708 | } \ 709 | inline std::string* name##Impl(int v1, int v2, const char* exprtext) { \ 710 | return name##Impl(v1, v2, exprtext); \ 711 | } 712 | 713 | // We use the full name Check_EQ, Check_NE, etc. in case the file including 714 | // base/logging.h provides its own #defines for the simpler names EQ, NE, etc. 715 | // This happens if, for example, those are used as token names in a 716 | // yacc grammar. 717 | DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)? 718 | DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead. 719 | DEFINE_CHECK_OP_IMPL(Check_LE, <=) 720 | DEFINE_CHECK_OP_IMPL(Check_LT, < ) 721 | DEFINE_CHECK_OP_IMPL(Check_GE, >=) 722 | DEFINE_CHECK_OP_IMPL(Check_GT, > ) 723 | #undef DEFINE_CHECK_OP_IMPL 724 | 725 | // Helper macro for binary operators. 726 | // Don't use this macro directly in your code, use CHECK_EQ et al below. 727 | 728 | #if defined(STATIC_ANALYSIS) 729 | // Only for static analysis tool to know that it is equivalent to assert 730 | #define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1) op (val2)) 731 | #elif DCHECK_IS_ON() 732 | // In debug mode, avoid constructing CheckOpStrings if possible, 733 | // to reduce the overhead of CHECK statments by 2x. 734 | // Real DCHECK-heavy tests have seen 1.5x speedups. 735 | 736 | // The meaning of "string" might be different between now and 737 | // when this macro gets invoked (e.g., if someone is experimenting 738 | // with other string implementations that get defined after this 739 | // file is included). Save the current meaning now and use it 740 | // in the macro. 741 | typedef std::string _Check_string; 742 | #define CHECK_OP_LOG(name, op, val1, val2, log) \ 743 | while (google::_Check_string* _result = \ 744 | google::Check##name##Impl( \ 745 | google::GetReferenceableValue(val1), \ 746 | google::GetReferenceableValue(val2), \ 747 | #val1 " " #op " " #val2)) \ 748 | log(__FILE__, __LINE__, \ 749 | google::CheckOpString(_result)).stream() 750 | #else 751 | // In optimized mode, use CheckOpString to hint to compiler that 752 | // the while condition is unlikely. 753 | #define CHECK_OP_LOG(name, op, val1, val2, log) \ 754 | while (google::CheckOpString _result = \ 755 | google::Check##name##Impl( \ 756 | google::GetReferenceableValue(val1), \ 757 | google::GetReferenceableValue(val2), \ 758 | #val1 " " #op " " #val2)) \ 759 | log(__FILE__, __LINE__, _result).stream() 760 | #endif // STATIC_ANALYSIS, DCHECK_IS_ON() 761 | 762 | #if GOOGLE_STRIP_LOG <= 3 763 | #define CHECK_OP(name, op, val1, val2) \ 764 | CHECK_OP_LOG(name, op, val1, val2, google::LogMessageFatal) 765 | #else 766 | #define CHECK_OP(name, op, val1, val2) \ 767 | CHECK_OP_LOG(name, op, val1, val2, google::NullStreamFatal) 768 | #endif // STRIP_LOG <= 3 769 | 770 | // Equality/Inequality checks - compare two values, and log a FATAL message 771 | // including the two values when the result is not as expected. The values 772 | // must have operator<<(ostream, ...) defined. 773 | // 774 | // You may append to the error message like so: 775 | // CHECK_NE(1, 2) << ": The world must be ending!"; 776 | // 777 | // We are very careful to ensure that each argument is evaluated exactly 778 | // once, and that anything which is legal to pass as a function argument is 779 | // legal here. In particular, the arguments may be temporary expressions 780 | // which will end up being destroyed at the end of the apparent statement, 781 | // for example: 782 | // CHECK_EQ(string("abc")[1], 'b'); 783 | // 784 | // WARNING: These don't compile correctly if one of the arguments is a pointer 785 | // and the other is NULL. To work around this, simply static_cast NULL to the 786 | // type of the desired pointer. 787 | 788 | #define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2) 789 | #define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2) 790 | #define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2) 791 | #define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2) 792 | #define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2) 793 | #define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2) 794 | 795 | // Check that the input is non NULL. This very useful in constructor 796 | // initializer lists. 797 | 798 | #define CHECK_NOTNULL(val) \ 799 | google::CheckNotNull(__FILE__, __LINE__, "'" #val "' Must be non NULL", (val)) 800 | 801 | // Helper functions for string comparisons. 802 | // To avoid bloat, the definitions are in logging.cc. 803 | #define DECLARE_CHECK_STROP_IMPL(func, expected) \ 804 | GOOGLE_GLOG_DLL_DECL std::string* Check##func##expected##Impl( \ 805 | const char* s1, const char* s2, const char* names); 806 | DECLARE_CHECK_STROP_IMPL(strcmp, true) 807 | DECLARE_CHECK_STROP_IMPL(strcmp, false) 808 | DECLARE_CHECK_STROP_IMPL(strcasecmp, true) 809 | DECLARE_CHECK_STROP_IMPL(strcasecmp, false) 810 | #undef DECLARE_CHECK_STROP_IMPL 811 | 812 | // Helper macro for string comparisons. 813 | // Don't use this macro directly in your code, use CHECK_STREQ et al below. 814 | #define CHECK_STROP(func, op, expected, s1, s2) \ 815 | while (google::CheckOpString _result = \ 816 | google::Check##func##expected##Impl((s1), (s2), \ 817 | #s1 " " #op " " #s2)) \ 818 | LOG(FATAL) << *_result.str_ 819 | 820 | 821 | // String (char*) equality/inequality checks. 822 | // CASE versions are case-insensitive. 823 | // 824 | // Note that "s1" and "s2" may be temporary strings which are destroyed 825 | // by the compiler at the end of the current "full expression" 826 | // (e.g. CHECK_STREQ(Foo().c_str(), Bar().c_str())). 827 | 828 | #define CHECK_STREQ(s1, s2) CHECK_STROP(strcmp, ==, true, s1, s2) 829 | #define CHECK_STRNE(s1, s2) CHECK_STROP(strcmp, !=, false, s1, s2) 830 | #define CHECK_STRCASEEQ(s1, s2) CHECK_STROP(strcasecmp, ==, true, s1, s2) 831 | #define CHECK_STRCASENE(s1, s2) CHECK_STROP(strcasecmp, !=, false, s1, s2) 832 | 833 | #define CHECK_INDEX(I,A) CHECK(I < (sizeof(A)/sizeof(A[0]))) 834 | #define CHECK_BOUND(B,A) CHECK(B <= (sizeof(A)/sizeof(A[0]))) 835 | 836 | #define CHECK_DOUBLE_EQ(val1, val2) \ 837 | do { \ 838 | CHECK_LE((val1), (val2)+0.000000000000001L); \ 839 | CHECK_GE((val1), (val2)-0.000000000000001L); \ 840 | } while (0) 841 | 842 | #define CHECK_NEAR(val1, val2, margin) \ 843 | do { \ 844 | CHECK_LE((val1), (val2)+(margin)); \ 845 | CHECK_GE((val1), (val2)-(margin)); \ 846 | } while (0) 847 | 848 | // perror()..googly style! 849 | // 850 | // PLOG() and PLOG_IF() and PCHECK() behave exactly like their LOG* and 851 | // CHECK equivalents with the addition that they postpend a description 852 | // of the current state of errno to their output lines. 853 | 854 | #define PLOG(severity) GOOGLE_PLOG(severity, 0).stream() 855 | 856 | #define GOOGLE_PLOG(severity, counter) \ 857 | google::ErrnoLogMessage( \ 858 | __FILE__, __LINE__, google::GLOG_ ## severity, counter, \ 859 | &google::LogMessage::SendToLog) 860 | 861 | #define PLOG_IF(severity, condition) \ 862 | !(condition) ? (void) 0 : google::LogMessageVoidify() & PLOG(severity) 863 | 864 | // A CHECK() macro that postpends errno if the condition is false. E.g. 865 | // 866 | // if (poll(fds, nfds, timeout) == -1) { PCHECK(errno == EINTR); ... } 867 | #define PCHECK(condition) \ 868 | PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN(!(condition))) \ 869 | << "Check failed: " #condition " " 870 | 871 | // A CHECK() macro that lets you assert the success of a function that 872 | // returns -1 and sets errno in case of an error. E.g. 873 | // 874 | // CHECK_ERR(mkdir(path, 0700)); 875 | // 876 | // or 877 | // 878 | // int fd = open(filename, flags); CHECK_ERR(fd) << ": open " << filename; 879 | #define CHECK_ERR(invocation) \ 880 | PLOG_IF(FATAL, GOOGLE_PREDICT_BRANCH_NOT_TAKEN((invocation) == -1)) \ 881 | << #invocation 882 | 883 | // Use macro expansion to create, for each use of LOG_EVERY_N(), static 884 | // variables with the __LINE__ expansion as part of the variable name. 885 | #define LOG_EVERY_N_VARNAME(base, line) LOG_EVERY_N_VARNAME_CONCAT(base, line) 886 | #define LOG_EVERY_N_VARNAME_CONCAT(base, line) base ## line 887 | 888 | #define LOG_OCCURRENCES LOG_EVERY_N_VARNAME(occurrences_, __LINE__) 889 | #define LOG_OCCURRENCES_MOD_N LOG_EVERY_N_VARNAME(occurrences_mod_n_, __LINE__) 890 | 891 | #define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \ 892 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ 893 | ++LOG_OCCURRENCES; \ 894 | if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ 895 | if (LOG_OCCURRENCES_MOD_N == 1) \ 896 | google::LogMessage( \ 897 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ 898 | &what_to_do).stream() 899 | 900 | #define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \ 901 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ 902 | ++LOG_OCCURRENCES; \ 903 | if (condition && \ 904 | ((LOG_OCCURRENCES_MOD_N=(LOG_OCCURRENCES_MOD_N + 1) % n) == (1 % n))) \ 905 | google::LogMessage( \ 906 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ 907 | &what_to_do).stream() 908 | 909 | #define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \ 910 | static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \ 911 | ++LOG_OCCURRENCES; \ 912 | if (++LOG_OCCURRENCES_MOD_N > n) LOG_OCCURRENCES_MOD_N -= n; \ 913 | if (LOG_OCCURRENCES_MOD_N == 1) \ 914 | google::ErrnoLogMessage( \ 915 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ 916 | &what_to_do).stream() 917 | 918 | #define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \ 919 | static int LOG_OCCURRENCES = 0; \ 920 | if (LOG_OCCURRENCES <= n) \ 921 | ++LOG_OCCURRENCES; \ 922 | if (LOG_OCCURRENCES <= n) \ 923 | google::LogMessage( \ 924 | __FILE__, __LINE__, google::GLOG_ ## severity, LOG_OCCURRENCES, \ 925 | &what_to_do).stream() 926 | 927 | namespace glog_internal_namespace_ { 928 | template 929 | struct CompileAssert { 930 | }; 931 | struct CrashReason; 932 | 933 | // Returns true if FailureSignalHandler is installed. 934 | // Needs to be exported since it's used by the signalhandler_unittest. 935 | GOOGLE_GLOG_DLL_DECL bool IsFailureSignalHandlerInstalled(); 936 | } // namespace glog_internal_namespace_ 937 | 938 | #define LOG_EVERY_N(severity, n) \ 939 | SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToLog) 940 | 941 | #define SYSLOG_EVERY_N(severity, n) \ 942 | SOME_KIND_OF_LOG_EVERY_N(severity, (n), google::LogMessage::SendToSyslogAndLog) 943 | 944 | #define PLOG_EVERY_N(severity, n) \ 945 | SOME_KIND_OF_PLOG_EVERY_N(severity, (n), google::LogMessage::SendToLog) 946 | 947 | #define LOG_FIRST_N(severity, n) \ 948 | SOME_KIND_OF_LOG_FIRST_N(severity, (n), google::LogMessage::SendToLog) 949 | 950 | #define LOG_IF_EVERY_N(severity, condition, n) \ 951 | SOME_KIND_OF_LOG_IF_EVERY_N(severity, (condition), (n), google::LogMessage::SendToLog) 952 | 953 | // We want the special COUNTER value available for LOG_EVERY_X()'ed messages 954 | enum PRIVATE_Counter {COUNTER}; 955 | 956 | #ifdef GLOG_NO_ABBREVIATED_SEVERITIES 957 | // wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets 958 | // substituted with 0, and it expands to COMPACT_GOOGLE_LOG_0. To allow us 959 | // to keep using this syntax, we define this macro to do the same thing 960 | // as COMPACT_GOOGLE_LOG_ERROR. 961 | #define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR 962 | #define SYSLOG_0 SYSLOG_ERROR 963 | #define LOG_TO_STRING_0 LOG_TO_STRING_ERROR 964 | // Needed for LOG_IS_ON(ERROR). 965 | const LogSeverity GLOG_0 = GLOG_ERROR; 966 | #else 967 | // Users may include windows.h after logging.h without 968 | // GLOG_NO_ABBREVIATED_SEVERITIES nor WIN32_LEAN_AND_MEAN. 969 | // For this case, we cannot detect if ERROR is defined before users 970 | // actually use ERROR. Let's make an undefined symbol to warn users. 971 | # define GLOG_ERROR_MSG ERROR_macro_is_defined_Define_GLOG_NO_ABBREVIATED_SEVERITIES_before_including_logging_h_See_the_document_for_detail 972 | # define COMPACT_GOOGLE_LOG_0 GLOG_ERROR_MSG 973 | # define SYSLOG_0 GLOG_ERROR_MSG 974 | # define LOG_TO_STRING_0 GLOG_ERROR_MSG 975 | # define GLOG_0 GLOG_ERROR_MSG 976 | #endif 977 | 978 | // Plus some debug-logging macros that get compiled to nothing for production 979 | 980 | #if DCHECK_IS_ON() 981 | 982 | #define DLOG(severity) LOG(severity) 983 | #define DVLOG(verboselevel) VLOG(verboselevel) 984 | #define DLOG_IF(severity, condition) LOG_IF(severity, condition) 985 | #define DLOG_EVERY_N(severity, n) LOG_EVERY_N(severity, n) 986 | #define DLOG_IF_EVERY_N(severity, condition, n) \ 987 | LOG_IF_EVERY_N(severity, condition, n) 988 | #define DLOG_ASSERT(condition) LOG_ASSERT(condition) 989 | 990 | // debug-only checking. executed if DCHECK_IS_ON(). 991 | #define DCHECK(condition) CHECK(condition) 992 | #define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2) 993 | #define DCHECK_NE(val1, val2) CHECK_NE(val1, val2) 994 | #define DCHECK_LE(val1, val2) CHECK_LE(val1, val2) 995 | #define DCHECK_LT(val1, val2) CHECK_LT(val1, val2) 996 | #define DCHECK_GE(val1, val2) CHECK_GE(val1, val2) 997 | #define DCHECK_GT(val1, val2) CHECK_GT(val1, val2) 998 | #define DCHECK_NOTNULL(val) CHECK_NOTNULL(val) 999 | #define DCHECK_STREQ(str1, str2) CHECK_STREQ(str1, str2) 1000 | #define DCHECK_STRCASEEQ(str1, str2) CHECK_STRCASEEQ(str1, str2) 1001 | #define DCHECK_STRNE(str1, str2) CHECK_STRNE(str1, str2) 1002 | #define DCHECK_STRCASENE(str1, str2) CHECK_STRCASENE(str1, str2) 1003 | 1004 | #else // !DCHECK_IS_ON() 1005 | 1006 | #define DLOG(severity) \ 1007 | true ? (void) 0 : google::LogMessageVoidify() & LOG(severity) 1008 | 1009 | #define DVLOG(verboselevel) \ 1010 | (true || !VLOG_IS_ON(verboselevel)) ?\ 1011 | (void) 0 : google::LogMessageVoidify() & LOG(INFO) 1012 | 1013 | #define DLOG_IF(severity, condition) \ 1014 | (true || !(condition)) ? (void) 0 : google::LogMessageVoidify() & LOG(severity) 1015 | 1016 | #define DLOG_EVERY_N(severity, n) \ 1017 | true ? (void) 0 : google::LogMessageVoidify() & LOG(severity) 1018 | 1019 | #define DLOG_IF_EVERY_N(severity, condition, n) \ 1020 | (true || !(condition))? (void) 0 : google::LogMessageVoidify() & LOG(severity) 1021 | 1022 | #define DLOG_ASSERT(condition) \ 1023 | true ? (void) 0 : LOG_ASSERT(condition) 1024 | 1025 | // MSVC warning C4127: conditional expression is constant 1026 | #define DCHECK(condition) \ 1027 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1028 | while (false) \ 1029 | GLOG_MSVC_POP_WARNING() CHECK(condition) 1030 | 1031 | #define DCHECK_EQ(val1, val2) \ 1032 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1033 | while (false) \ 1034 | GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2) 1035 | 1036 | #define DCHECK_NE(val1, val2) \ 1037 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1038 | while (false) \ 1039 | GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2) 1040 | 1041 | #define DCHECK_LE(val1, val2) \ 1042 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1043 | while (false) \ 1044 | GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2) 1045 | 1046 | #define DCHECK_LT(val1, val2) \ 1047 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1048 | while (false) \ 1049 | GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2) 1050 | 1051 | #define DCHECK_GE(val1, val2) \ 1052 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1053 | while (false) \ 1054 | GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2) 1055 | 1056 | #define DCHECK_GT(val1, val2) \ 1057 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1058 | while (false) \ 1059 | GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2) 1060 | 1061 | // You may see warnings in release mode if you don't use the return 1062 | // value of DCHECK_NOTNULL. Please just use DCHECK for such cases. 1063 | #define DCHECK_NOTNULL(val) (val) 1064 | 1065 | #define DCHECK_STREQ(str1, str2) \ 1066 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1067 | while (false) \ 1068 | GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2) 1069 | 1070 | #define DCHECK_STRCASEEQ(str1, str2) \ 1071 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1072 | while (false) \ 1073 | GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2) 1074 | 1075 | #define DCHECK_STRNE(str1, str2) \ 1076 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1077 | while (false) \ 1078 | GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2) 1079 | 1080 | #define DCHECK_STRCASENE(str1, str2) \ 1081 | GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ 1082 | while (false) \ 1083 | GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2) 1084 | 1085 | #endif // DCHECK_IS_ON() 1086 | 1087 | // Log only in verbose mode. 1088 | 1089 | #define VLOG(verboselevel) LOG_IF(INFO, VLOG_IS_ON(verboselevel)) 1090 | 1091 | #define VLOG_IF(verboselevel, condition) \ 1092 | LOG_IF(INFO, (condition) && VLOG_IS_ON(verboselevel)) 1093 | 1094 | #define VLOG_EVERY_N(verboselevel, n) \ 1095 | LOG_IF_EVERY_N(INFO, VLOG_IS_ON(verboselevel), n) 1096 | 1097 | #define VLOG_IF_EVERY_N(verboselevel, condition, n) \ 1098 | LOG_IF_EVERY_N(INFO, (condition) && VLOG_IS_ON(verboselevel), n) 1099 | 1100 | namespace base_logging { 1101 | 1102 | // LogMessage::LogStream is a std::ostream backed by this streambuf. 1103 | // This class ignores overflow and leaves two bytes at the end of the 1104 | // buffer to allow for a '\n' and '\0'. 1105 | class GOOGLE_GLOG_DLL_DECL LogStreamBuf : public std::streambuf { 1106 | public: 1107 | // REQUIREMENTS: "len" must be >= 2 to account for the '\n' and '\n'. 1108 | LogStreamBuf(char *buf, int len) { 1109 | setp(buf, buf + len - 2); 1110 | } 1111 | 1112 | // This effectively ignores overflow. 1113 | virtual int_type overflow(int_type ch) { 1114 | return ch; 1115 | } 1116 | 1117 | // Legacy public ostrstream method. 1118 | size_t pcount() const { return pptr() - pbase(); } 1119 | char* pbase() const { return std::streambuf::pbase(); } 1120 | }; 1121 | 1122 | } // namespace base_logging 1123 | 1124 | // 1125 | // This class more or less represents a particular log message. You 1126 | // create an instance of LogMessage and then stream stuff to it. 1127 | // When you finish streaming to it, ~LogMessage is called and the 1128 | // full message gets streamed to the appropriate destination. 1129 | // 1130 | // You shouldn't actually use LogMessage's constructor to log things, 1131 | // though. You should use the LOG() macro (and variants thereof) 1132 | // above. 1133 | class GOOGLE_GLOG_DLL_DECL LogMessage { 1134 | public: 1135 | enum { 1136 | // Passing kNoLogPrefix for the line number disables the 1137 | // log-message prefix. Useful for using the LogMessage 1138 | // infrastructure as a printing utility. See also the --log_prefix 1139 | // flag for controlling the log-message prefix on an 1140 | // application-wide basis. 1141 | kNoLogPrefix = -1 1142 | }; 1143 | 1144 | // LogStream inherit from non-DLL-exported class (std::ostrstream) 1145 | // and VC++ produces a warning for this situation. 1146 | // However, MSDN says "C4275 can be ignored in Microsoft Visual C++ 1147 | // 2005 if you are deriving from a type in the Standard C++ Library" 1148 | // http://msdn.microsoft.com/en-us/library/3tdb471s(VS.80).aspx 1149 | // Let's just ignore the warning. 1150 | #ifdef _MSC_VER 1151 | # pragma warning(push) 1152 | # pragma warning(disable: 4275) 1153 | #endif 1154 | class GOOGLE_GLOG_DLL_DECL LogStream : public std::ostream { 1155 | #ifdef _MSC_VER 1156 | # pragma warning(pop) 1157 | #endif 1158 | public: 1159 | LogStream(char *buf, int len, int ctr) 1160 | : std::ostream(NULL), 1161 | streambuf_(buf, len), 1162 | ctr_(ctr), 1163 | self_(this) { 1164 | rdbuf(&streambuf_); 1165 | } 1166 | 1167 | int ctr() const { return ctr_; } 1168 | void set_ctr(int ctr) { ctr_ = ctr; } 1169 | LogStream* self() const { return self_; } 1170 | 1171 | // Legacy std::streambuf methods. 1172 | size_t pcount() const { return streambuf_.pcount(); } 1173 | char* pbase() const { return streambuf_.pbase(); } 1174 | char* str() const { return pbase(); } 1175 | 1176 | private: 1177 | LogStream(const LogStream&); 1178 | LogStream& operator=(const LogStream&); 1179 | base_logging::LogStreamBuf streambuf_; 1180 | int ctr_; // Counter hack (for the LOG_EVERY_X() macro) 1181 | LogStream *self_; // Consistency check hack 1182 | }; 1183 | 1184 | public: 1185 | // icc 8 requires this typedef to avoid an internal compiler error. 1186 | typedef void (LogMessage::*SendMethod)(); 1187 | 1188 | LogMessage(const char* file, int line, LogSeverity severity, int ctr, 1189 | SendMethod send_method); 1190 | 1191 | // Two special constructors that generate reduced amounts of code at 1192 | // LOG call sites for common cases. 1193 | 1194 | // Used for LOG(INFO): Implied are: 1195 | // severity = INFO, ctr = 0, send_method = &LogMessage::SendToLog. 1196 | // 1197 | // Using this constructor instead of the more complex constructor above 1198 | // saves 19 bytes per call site. 1199 | LogMessage(const char* file, int line); 1200 | 1201 | // Used for LOG(severity) where severity != INFO. Implied 1202 | // are: ctr = 0, send_method = &LogMessage::SendToLog 1203 | // 1204 | // Using this constructor instead of the more complex constructor above 1205 | // saves 17 bytes per call site. 1206 | LogMessage(const char* file, int line, LogSeverity severity); 1207 | 1208 | // Constructor to log this message to a specified sink (if not NULL). 1209 | // Implied are: ctr = 0, send_method = &LogMessage::SendToSinkAndLog if 1210 | // also_send_to_log is true, send_method = &LogMessage::SendToSink otherwise. 1211 | LogMessage(const char* file, int line, LogSeverity severity, LogSink* sink, 1212 | bool also_send_to_log); 1213 | 1214 | // Constructor where we also give a vector pointer 1215 | // for storing the messages (if the pointer is not NULL). 1216 | // Implied are: ctr = 0, send_method = &LogMessage::SaveOrSendToLog. 1217 | LogMessage(const char* file, int line, LogSeverity severity, 1218 | std::vector* outvec); 1219 | 1220 | // Constructor where we also give a string pointer for storing the 1221 | // message (if the pointer is not NULL). Implied are: ctr = 0, 1222 | // send_method = &LogMessage::WriteToStringAndLog. 1223 | LogMessage(const char* file, int line, LogSeverity severity, 1224 | std::string* message); 1225 | 1226 | // A special constructor used for check failures 1227 | LogMessage(const char* file, int line, const CheckOpString& result); 1228 | 1229 | ~LogMessage(); 1230 | 1231 | // Flush a buffered message to the sink set in the constructor. Always 1232 | // called by the destructor, it may also be called from elsewhere if 1233 | // needed. Only the first call is actioned; any later ones are ignored. 1234 | void Flush(); 1235 | 1236 | // An arbitrary limit on the length of a single log message. This 1237 | // is so that streaming can be done more efficiently. 1238 | static const size_t kMaxLogMessageLen; 1239 | 1240 | // Theses should not be called directly outside of logging.*, 1241 | // only passed as SendMethod arguments to other LogMessage methods: 1242 | void SendToLog(); // Actually dispatch to the logs 1243 | void SendToSyslogAndLog(); // Actually dispatch to syslog and the logs 1244 | 1245 | // Call abort() or similar to perform LOG(FATAL) crash. 1246 | static void __declspec(noreturn) Fail(); 1247 | 1248 | std::ostream& stream(); 1249 | 1250 | int preserved_errno() const; 1251 | 1252 | // Must be called without the log_mutex held. (L < log_mutex) 1253 | static int64 num_messages(int severity); 1254 | 1255 | struct LogMessageData; 1256 | 1257 | private: 1258 | // Fully internal SendMethod cases: 1259 | void SendToSinkAndLog(); // Send to sink if provided and dispatch to the logs 1260 | void SendToSink(); // Send to sink if provided, do nothing otherwise. 1261 | 1262 | // Write to string if provided and dispatch to the logs. 1263 | void WriteToStringAndLog(); 1264 | 1265 | void SaveOrSendToLog(); // Save to stringvec if provided, else to logs 1266 | 1267 | void Init(const char* file, int line, LogSeverity severity, 1268 | void (LogMessage::*send_method)()); 1269 | 1270 | // Used to fill in crash information during LOG(FATAL) failures. 1271 | void RecordCrashReason(glog_internal_namespace_::CrashReason* reason); 1272 | 1273 | // Counts of messages sent at each priority: 1274 | static int64 num_messages_[NUM_SEVERITIES]; // under log_mutex 1275 | 1276 | // We keep the data in a separate struct so that each instance of 1277 | // LogMessage uses less stack space. 1278 | LogMessageData* allocated_; 1279 | LogMessageData* data_; 1280 | 1281 | friend class LogDestination; 1282 | 1283 | LogMessage(const LogMessage&); 1284 | void operator=(const LogMessage&); 1285 | }; 1286 | 1287 | // This class happens to be thread-hostile because all instances share 1288 | // a single data buffer, but since it can only be created just before 1289 | // the process dies, we don't worry so much. 1290 | class GOOGLE_GLOG_DLL_DECL LogMessageFatal : public LogMessage { 1291 | public: 1292 | LogMessageFatal(const char* file, int line); 1293 | LogMessageFatal(const char* file, int line, const CheckOpString& result); 1294 | __declspec(noreturn) ~LogMessageFatal(); 1295 | }; 1296 | 1297 | // A non-macro interface to the log facility; (useful 1298 | // when the logging level is not a compile-time constant). 1299 | inline void LogAtLevel(int const severity, std::string const &msg) { 1300 | LogMessage(__FILE__, __LINE__, severity).stream() << msg; 1301 | } 1302 | 1303 | // A macro alternative of LogAtLevel. New code may want to use this 1304 | // version since there are two advantages: 1. this version outputs the 1305 | // file name and the line number where this macro is put like other 1306 | // LOG macros, 2. this macro can be used as C++ stream. 1307 | #define LOG_AT_LEVEL(severity) google::LogMessage(__FILE__, __LINE__, severity).stream() 1308 | 1309 | // Check if it's compiled in C++11 mode. 1310 | // 1311 | // GXX_EXPERIMENTAL_CXX0X is defined by gcc and clang up to at least 1312 | // gcc-4.7 and clang-3.1 (2011-12-13). __cplusplus was defined to 1 1313 | // in gcc before 4.7 (Crosstool 16) and clang before 3.1, but is 1314 | // defined according to the language version in effect thereafter. 1315 | // Microsoft Visual Studio 14 (2015) sets __cplusplus==199711 despite 1316 | // reasonably good C++11 support, so we set LANG_CXX for it and 1317 | // newer versions (_MSC_VER >= 1900). 1318 | #if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \ 1319 | (defined(_MSC_VER) && _MSC_VER >= 1900)) 1320 | // Helper for CHECK_NOTNULL(). 1321 | // 1322 | // In C++11, all cases can be handled by a single function. Since the value 1323 | // category of the argument is preserved (also for rvalue references), 1324 | // member initializer lists like the one below will compile correctly: 1325 | // 1326 | // Foo() 1327 | // : x_(CHECK_NOTNULL(MethodReturningUniquePtr())) {} 1328 | template 1329 | T CheckNotNull(const char* file, int line, const char* names, T&& t) { 1330 | if (t == nullptr) { 1331 | LogMessageFatal(file, line, new std::string(names)); 1332 | } 1333 | return std::forward(t); 1334 | } 1335 | 1336 | #else 1337 | 1338 | // A small helper for CHECK_NOTNULL(). 1339 | template 1340 | T* CheckNotNull(const char *file, int line, const char *names, T* t) { 1341 | if (t == NULL) { 1342 | LogMessageFatal(file, line, new std::string(names)); 1343 | } 1344 | return t; 1345 | } 1346 | #endif 1347 | 1348 | // Allow folks to put a counter in the LOG_EVERY_X()'ed messages. This 1349 | // only works if ostream is a LogStream. If the ostream is not a 1350 | // LogStream you'll get an assert saying as much at runtime. 1351 | GOOGLE_GLOG_DLL_DECL std::ostream& operator<<(std::ostream &os, 1352 | const PRIVATE_Counter&); 1353 | 1354 | 1355 | // Derived class for PLOG*() above. 1356 | class GOOGLE_GLOG_DLL_DECL ErrnoLogMessage : public LogMessage { 1357 | public: 1358 | 1359 | ErrnoLogMessage(const char* file, int line, LogSeverity severity, int ctr, 1360 | void (LogMessage::*send_method)()); 1361 | 1362 | // Postpends ": strerror(errno) [errno]". 1363 | ~ErrnoLogMessage(); 1364 | 1365 | private: 1366 | ErrnoLogMessage(const ErrnoLogMessage&); 1367 | void operator=(const ErrnoLogMessage&); 1368 | }; 1369 | 1370 | 1371 | // This class is used to explicitly ignore values in the conditional 1372 | // logging macros. This avoids compiler warnings like "value computed 1373 | // is not used" and "statement has no effect". 1374 | 1375 | class GOOGLE_GLOG_DLL_DECL LogMessageVoidify { 1376 | public: 1377 | LogMessageVoidify() { } 1378 | // This has to be an operator with a precedence lower than << but 1379 | // higher than ?: 1380 | void operator&(std::ostream&) { } 1381 | }; 1382 | 1383 | 1384 | // Flushes all log files that contains messages that are at least of 1385 | // the specified severity level. Thread-safe. 1386 | GOOGLE_GLOG_DLL_DECL void FlushLogFiles(LogSeverity min_severity); 1387 | 1388 | // Flushes all log files that contains messages that are at least of 1389 | // the specified severity level. Thread-hostile because it ignores 1390 | // locking -- used for catastrophic failures. 1391 | GOOGLE_GLOG_DLL_DECL void FlushLogFilesUnsafe(LogSeverity min_severity); 1392 | 1393 | // 1394 | // Set the destination to which a particular severity level of log 1395 | // messages is sent. If base_filename is "", it means "don't log this 1396 | // severity". Thread-safe. 1397 | // 1398 | GOOGLE_GLOG_DLL_DECL void SetLogDestination(LogSeverity severity, 1399 | const char* base_filename); 1400 | 1401 | // 1402 | // Set the basename of the symlink to the latest log file at a given 1403 | // severity. If symlink_basename is empty, do not make a symlink. If 1404 | // you don't call this function, the symlink basename is the 1405 | // invocation name of the program. Thread-safe. 1406 | // 1407 | GOOGLE_GLOG_DLL_DECL void SetLogSymlink(LogSeverity severity, 1408 | const char* symlink_basename); 1409 | 1410 | // 1411 | // Used to send logs to some other kind of destination 1412 | // Users should subclass LogSink and override send to do whatever they want. 1413 | // Implementations must be thread-safe because a shared instance will 1414 | // be called from whichever thread ran the LOG(XXX) line. 1415 | class GOOGLE_GLOG_DLL_DECL LogSink { 1416 | public: 1417 | virtual ~LogSink(); 1418 | 1419 | // Sink's logging logic (message_len is such as to exclude '\n' at the end). 1420 | // This method can't use LOG() or CHECK() as logging system mutex(s) are held 1421 | // during this call. 1422 | virtual void send(LogSeverity severity, const char* full_filename, 1423 | const char* base_filename, int line, 1424 | const struct ::tm* tm_time, 1425 | const char* message, size_t message_len) = 0; 1426 | 1427 | // Redefine this to implement waiting for 1428 | // the sink's logging logic to complete. 1429 | // It will be called after each send() returns, 1430 | // but before that LogMessage exits or crashes. 1431 | // By default this function does nothing. 1432 | // Using this function one can implement complex logic for send() 1433 | // that itself involves logging; and do all this w/o causing deadlocks and 1434 | // inconsistent rearrangement of log messages. 1435 | // E.g. if a LogSink has thread-specific actions, the send() method 1436 | // can simply add the message to a queue and wake up another thread that 1437 | // handles real logging while itself making some LOG() calls; 1438 | // WaitTillSent() can be implemented to wait for that logic to complete. 1439 | // See our unittest for an example. 1440 | virtual void WaitTillSent(); 1441 | 1442 | // Returns the normal text output of the log message. 1443 | // Can be useful to implement send(). 1444 | static std::string ToString(LogSeverity severity, const char* file, int line, 1445 | const struct ::tm* tm_time, 1446 | const char* message, size_t message_len); 1447 | }; 1448 | 1449 | // Add or remove a LogSink as a consumer of logging data. Thread-safe. 1450 | GOOGLE_GLOG_DLL_DECL void AddLogSink(LogSink *destination); 1451 | GOOGLE_GLOG_DLL_DECL void RemoveLogSink(LogSink *destination); 1452 | 1453 | // 1454 | // Specify an "extension" added to the filename specified via 1455 | // SetLogDestination. This applies to all severity levels. It's 1456 | // often used to append the port we're listening on to the logfile 1457 | // name. Thread-safe. 1458 | // 1459 | GOOGLE_GLOG_DLL_DECL void SetLogFilenameExtension( 1460 | const char* filename_extension); 1461 | 1462 | // 1463 | // Make it so that all log messages of at least a particular severity 1464 | // are logged to stderr (in addition to logging to the usual log 1465 | // file(s)). Thread-safe. 1466 | // 1467 | GOOGLE_GLOG_DLL_DECL void SetStderrLogging(LogSeverity min_severity); 1468 | 1469 | // 1470 | // Make it so that all log messages go only to stderr. Thread-safe. 1471 | // 1472 | GOOGLE_GLOG_DLL_DECL void LogToStderr(); 1473 | 1474 | // 1475 | // Make it so that all log messages of at least a particular severity are 1476 | // logged via email to a list of addresses (in addition to logging to the 1477 | // usual log file(s)). The list of addresses is just a string containing 1478 | // the email addresses to send to (separated by spaces, say). Thread-safe. 1479 | // 1480 | GOOGLE_GLOG_DLL_DECL void SetEmailLogging(LogSeverity min_severity, 1481 | const char* addresses); 1482 | 1483 | // A simple function that sends email. dest is a commma-separated 1484 | // list of addressess. Thread-safe. 1485 | GOOGLE_GLOG_DLL_DECL bool SendEmail(const char *dest, 1486 | const char *subject, const char *body); 1487 | 1488 | GOOGLE_GLOG_DLL_DECL const std::vector& GetLoggingDirectories(); 1489 | 1490 | // For tests only: Clear the internal [cached] list of logging directories to 1491 | // force a refresh the next time GetLoggingDirectories is called. 1492 | // Thread-hostile. 1493 | void TestOnly_ClearLoggingDirectoriesList(); 1494 | 1495 | // Returns a set of existing temporary directories, which will be a 1496 | // subset of the directories returned by GetLogginDirectories(). 1497 | // Thread-safe. 1498 | GOOGLE_GLOG_DLL_DECL void GetExistingTempDirectories( 1499 | std::vector* list); 1500 | 1501 | // Print any fatal message again -- useful to call from signal handler 1502 | // so that the last thing in the output is the fatal message. 1503 | // Thread-hostile, but a race is unlikely. 1504 | GOOGLE_GLOG_DLL_DECL void ReprintFatalMessage(); 1505 | 1506 | // Truncate a log file that may be the append-only output of multiple 1507 | // processes and hence can't simply be renamed/reopened (typically a 1508 | // stdout/stderr). If the file "path" is > "limit" bytes, copy the 1509 | // last "keep" bytes to offset 0 and truncate the rest. Since we could 1510 | // be racing with other writers, this approach has the potential to 1511 | // lose very small amounts of data. For security, only follow symlinks 1512 | // if the path is /proc/self/fd/* 1513 | GOOGLE_GLOG_DLL_DECL void TruncateLogFile(const char *path, 1514 | int64 limit, int64 keep); 1515 | 1516 | // Truncate stdout and stderr if they are over the value specified by 1517 | // --max_log_size; keep the final 1MB. This function has the same 1518 | // race condition as TruncateLogFile. 1519 | GOOGLE_GLOG_DLL_DECL void TruncateStdoutStderr(); 1520 | 1521 | // Return the string representation of the provided LogSeverity level. 1522 | // Thread-safe. 1523 | GOOGLE_GLOG_DLL_DECL const char* GetLogSeverityName(LogSeverity severity); 1524 | 1525 | // --------------------------------------------------------------------- 1526 | // Implementation details that are not useful to most clients 1527 | // --------------------------------------------------------------------- 1528 | 1529 | // A Logger is the interface used by logging modules to emit entries 1530 | // to a log. A typical implementation will dump formatted data to a 1531 | // sequence of files. We also provide interfaces that will forward 1532 | // the data to another thread so that the invoker never blocks. 1533 | // Implementations should be thread-safe since the logging system 1534 | // will write to them from multiple threads. 1535 | 1536 | namespace base { 1537 | 1538 | class GOOGLE_GLOG_DLL_DECL Logger { 1539 | public: 1540 | virtual ~Logger(); 1541 | 1542 | // Writes "message[0,message_len-1]" corresponding to an event that 1543 | // occurred at "timestamp". If "force_flush" is true, the log file 1544 | // is flushed immediately. 1545 | // 1546 | // The input message has already been formatted as deemed 1547 | // appropriate by the higher level logging facility. For example, 1548 | // textual log messages already contain timestamps, and the 1549 | // file:linenumber header. 1550 | virtual void Write(bool force_flush, 1551 | time_t timestamp, 1552 | const char* message, 1553 | int message_len) = 0; 1554 | 1555 | // Flush any buffered messages 1556 | virtual void Flush() = 0; 1557 | 1558 | // Get the current LOG file size. 1559 | // The returned value is approximate since some 1560 | // logged data may not have been flushed to disk yet. 1561 | virtual uint32 LogSize() = 0; 1562 | }; 1563 | 1564 | // Get the logger for the specified severity level. The logger 1565 | // remains the property of the logging module and should not be 1566 | // deleted by the caller. Thread-safe. 1567 | extern GOOGLE_GLOG_DLL_DECL Logger* GetLogger(LogSeverity level); 1568 | 1569 | // Set the logger for the specified severity level. The logger 1570 | // becomes the property of the logging module and should not 1571 | // be deleted by the caller. Thread-safe. 1572 | extern GOOGLE_GLOG_DLL_DECL void SetLogger(LogSeverity level, Logger* logger); 1573 | 1574 | } 1575 | 1576 | // glibc has traditionally implemented two incompatible versions of 1577 | // strerror_r(). There is a poorly defined convention for picking the 1578 | // version that we want, but it is not clear whether it even works with 1579 | // all versions of glibc. 1580 | // So, instead, we provide this wrapper that automatically detects the 1581 | // version that is in use, and then implements POSIX semantics. 1582 | // N.B. In addition to what POSIX says, we also guarantee that "buf" will 1583 | // be set to an empty string, if this function failed. This means, in most 1584 | // cases, you do not need to check the error code and you can directly 1585 | // use the value of "buf". It will never have an undefined value. 1586 | // DEPRECATED: Use StrError(int) instead. 1587 | GOOGLE_GLOG_DLL_DECL int posix_strerror_r(int err, char *buf, size_t len); 1588 | 1589 | // A thread-safe replacement for strerror(). Returns a string describing the 1590 | // given POSIX error code. 1591 | GOOGLE_GLOG_DLL_DECL std::string StrError(int err); 1592 | 1593 | // A class for which we define operator<<, which does nothing. 1594 | class GOOGLE_GLOG_DLL_DECL NullStream : public LogMessage::LogStream { 1595 | public: 1596 | // Initialize the LogStream so the messages can be written somewhere 1597 | // (they'll never be actually displayed). This will be needed if a 1598 | // NullStream& is implicitly converted to LogStream&, in which case 1599 | // the overloaded NullStream::operator<< will not be invoked. 1600 | NullStream() : LogMessage::LogStream(message_buffer_, 1, 0) { } 1601 | NullStream(const char* /*file*/, int /*line*/, 1602 | const CheckOpString& /*result*/) : 1603 | LogMessage::LogStream(message_buffer_, 1, 0) { } 1604 | NullStream &stream() { return *this; } 1605 | private: 1606 | // A very short buffer for messages (which we discard anyway). This 1607 | // will be needed if NullStream& converted to LogStream& (e.g. as a 1608 | // result of a conditional expression). 1609 | char message_buffer_[2]; 1610 | }; 1611 | 1612 | // Do nothing. This operator is inline, allowing the message to be 1613 | // compiled away. The message will not be compiled away if we do 1614 | // something like (flag ? LOG(INFO) : LOG(ERROR)) << message; when 1615 | // SKIP_LOG=WARNING. In those cases, NullStream will be implicitly 1616 | // converted to LogStream and the message will be computed and then 1617 | // quietly discarded. 1618 | template 1619 | inline NullStream& operator<<(NullStream &str, const T &) { return str; } 1620 | 1621 | // Similar to NullStream, but aborts the program (without stack 1622 | // trace), like LogMessageFatal. 1623 | class GOOGLE_GLOG_DLL_DECL NullStreamFatal : public NullStream { 1624 | public: 1625 | NullStreamFatal() { } 1626 | NullStreamFatal(const char* file, int line, const CheckOpString& result) : 1627 | NullStream(file, line, result) { } 1628 | __declspec(noreturn) ~NullStreamFatal() throw () { _exit(1); } 1629 | }; 1630 | 1631 | // Install a signal handler that will dump signal information and a stack 1632 | // trace when the program crashes on certain signals. We'll install the 1633 | // signal handler for the following signals. 1634 | // 1635 | // SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, and SIGTERM. 1636 | // 1637 | // By default, the signal handler will write the failure dump to the 1638 | // standard error. You can customize the destination by installing your 1639 | // own writer function by InstallFailureWriter() below. 1640 | // 1641 | // Note on threading: 1642 | // 1643 | // The function should be called before threads are created, if you want 1644 | // to use the failure signal handler for all threads. The stack trace 1645 | // will be shown only for the thread that receives the signal. In other 1646 | // words, stack traces of other threads won't be shown. 1647 | GOOGLE_GLOG_DLL_DECL void InstallFailureSignalHandler(); 1648 | 1649 | // Installs a function that is used for writing the failure dump. "data" 1650 | // is the pointer to the beginning of a message to be written, and "size" 1651 | // is the size of the message. You should not expect the data is 1652 | // terminated with '\0'. 1653 | GOOGLE_GLOG_DLL_DECL void InstallFailureWriter( 1654 | void (*writer)(const char* data, int size)); 1655 | 1656 | } 1657 | 1658 | #endif // _LOGGING_H_ 1659 | -------------------------------------------------------------------------------- /third party/glog/include/raw_logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Author: Maxim Lifantsev 31 | // 32 | // Thread-safe logging routines that do not allocate any memory or 33 | // acquire any locks, and can therefore be used by low-level memory 34 | // allocation and synchronization code. 35 | 36 | #ifndef BASE_RAW_LOGGING_H_ 37 | #define BASE_RAW_LOGGING_H_ 38 | 39 | #include 40 | 41 | namespace google { 42 | 43 | #include "glog/log_severity.h" 44 | #include "glog/vlog_is_on.h" 45 | 46 | // Annoying stuff for windows -- makes sure clients can import these functions 47 | #ifndef GOOGLE_GLOG_DLL_DECL 48 | # if defined(_WIN32) && !defined(__CYGWIN__) 49 | # define GOOGLE_GLOG_DLL_DECL __declspec(dllimport) 50 | # else 51 | # define GOOGLE_GLOG_DLL_DECL 52 | # endif 53 | #endif 54 | 55 | // This is similar to LOG(severity) << format... and VLOG(level) << format.., 56 | // but 57 | // * it is to be used ONLY by low-level modules that can't use normal LOG() 58 | // * it is desiged to be a low-level logger that does not allocate any 59 | // memory and does not need any locks, hence: 60 | // * it logs straight and ONLY to STDERR w/o buffering 61 | // * it uses an explicit format and arguments list 62 | // * it will silently chop off really long message strings 63 | // Usage example: 64 | // RAW_LOG(ERROR, "Failed foo with %i: %s", status, error); 65 | // RAW_VLOG(3, "status is %i", status); 66 | // These will print an almost standard log lines like this to stderr only: 67 | // E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file 68 | // I0821 211317 file.cc:142] RAW: status is 20 69 | #define RAW_LOG(severity, ...) \ 70 | do { \ 71 | switch (google::GLOG_ ## severity) { \ 72 | case 0: \ 73 | RAW_LOG_INFO(__VA_ARGS__); \ 74 | break; \ 75 | case 1: \ 76 | RAW_LOG_WARNING(__VA_ARGS__); \ 77 | break; \ 78 | case 2: \ 79 | RAW_LOG_ERROR(__VA_ARGS__); \ 80 | break; \ 81 | case 3: \ 82 | RAW_LOG_FATAL(__VA_ARGS__); \ 83 | break; \ 84 | default: \ 85 | break; \ 86 | } \ 87 | } while (0) 88 | 89 | // The following STRIP_LOG testing is performed in the header file so that it's 90 | // possible to completely compile out the logging code and the log messages. 91 | #if STRIP_LOG == 0 92 | #define RAW_VLOG(verboselevel, ...) \ 93 | do { \ 94 | if (VLOG_IS_ON(verboselevel)) { \ 95 | RAW_LOG_INFO(__VA_ARGS__); \ 96 | } \ 97 | } while (0) 98 | #else 99 | #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__) 100 | #endif // STRIP_LOG == 0 101 | 102 | #if STRIP_LOG == 0 103 | #define RAW_LOG_INFO(...) google::RawLog__(google::GLOG_INFO, \ 104 | __FILE__, __LINE__, __VA_ARGS__) 105 | #else 106 | #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__) 107 | #endif // STRIP_LOG == 0 108 | 109 | #if STRIP_LOG <= 1 110 | #define RAW_LOG_WARNING(...) google::RawLog__(google::GLOG_WARNING, \ 111 | __FILE__, __LINE__, __VA_ARGS__) 112 | #else 113 | #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__) 114 | #endif // STRIP_LOG <= 1 115 | 116 | #if STRIP_LOG <= 2 117 | #define RAW_LOG_ERROR(...) google::RawLog__(google::GLOG_ERROR, \ 118 | __FILE__, __LINE__, __VA_ARGS__) 119 | #else 120 | #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__) 121 | #endif // STRIP_LOG <= 2 122 | 123 | #if STRIP_LOG <= 3 124 | #define RAW_LOG_FATAL(...) google::RawLog__(google::GLOG_FATAL, \ 125 | __FILE__, __LINE__, __VA_ARGS__) 126 | #else 127 | #define RAW_LOG_FATAL(...) \ 128 | do { \ 129 | google::RawLogStub__(0, __VA_ARGS__); \ 130 | exit(1); \ 131 | } while (0) 132 | #endif // STRIP_LOG <= 3 133 | 134 | // Similar to CHECK(condition) << message, 135 | // but for low-level modules: we use only RAW_LOG that does not allocate memory. 136 | // We do not want to provide args list here to encourage this usage: 137 | // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args); 138 | // so that the args are not computed when not needed. 139 | #define RAW_CHECK(condition, message) \ 140 | do { \ 141 | if (!(condition)) { \ 142 | RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \ 143 | } \ 144 | } while (0) 145 | 146 | // Debug versions of RAW_LOG and RAW_CHECK 147 | #ifndef NDEBUG 148 | 149 | #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__) 150 | #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message) 151 | 152 | #else // NDEBUG 153 | 154 | #define RAW_DLOG(severity, ...) \ 155 | while (false) \ 156 | RAW_LOG(severity, __VA_ARGS__) 157 | #define RAW_DCHECK(condition, message) \ 158 | while (false) \ 159 | RAW_CHECK(condition, message) 160 | 161 | #endif // NDEBUG 162 | 163 | // Stub log function used to work around for unused variable warnings when 164 | // building with STRIP_LOG > 0. 165 | static inline void RawLogStub__(int /* ignored */, ...) { 166 | } 167 | 168 | // Helper function to implement RAW_LOG and RAW_VLOG 169 | // Logs format... at "severity" level, reporting it 170 | // as called from file:line. 171 | // This does not allocate memory or acquire locks. 172 | GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity, 173 | const char* file, 174 | int line, 175 | const char* format, ...) 176 | ; 177 | 178 | // Hack to propagate time information into this module so that 179 | // this module does not have to directly call localtime_r(), 180 | // which could allocate memory. 181 | GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct tm& t, int usecs); 182 | 183 | } 184 | 185 | #endif // BASE_RAW_LOGGING_H_ 186 | -------------------------------------------------------------------------------- /third party/glog/include/stl_logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2003, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Stream output operators for STL containers; to be used for logging *only*. 31 | // Inclusion of this file lets you do: 32 | // 33 | // list x; 34 | // LOG(INFO) << "data: " << x; 35 | // vector v1, v2; 36 | // CHECK_EQ(v1, v2); 37 | // 38 | // If you want to use this header file with hash maps or slist, you 39 | // need to define macros before including this file: 40 | // 41 | // - GLOG_STL_LOGGING_FOR_UNORDERED - and 42 | // - GLOG_STL_LOGGING_FOR_TR1_UNORDERED - 43 | // - GLOG_STL_LOGGING_FOR_EXT_HASH - 44 | // - GLOG_STL_LOGGING_FOR_EXT_SLIST - 45 | // 46 | 47 | #ifndef UTIL_GTL_STL_LOGGING_INL_H_ 48 | #define UTIL_GTL_STL_LOGGING_INL_H_ 49 | 50 | #if !1 51 | # error We do not support stl_logging for this compiler 52 | #endif 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED 63 | # include 64 | # include 65 | #endif 66 | 67 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED 68 | # include 69 | # include 70 | #endif 71 | 72 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH 73 | # include 74 | # include 75 | #endif 76 | #ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST 77 | # include 78 | #endif 79 | 80 | // Forward declare these two, and define them after all the container streams 81 | // operators so that we can recurse from pair -> container -> container -> pair 82 | // properly. 83 | template 84 | std::ostream& operator<<(std::ostream& out, const std::pair& p); 85 | 86 | namespace google { 87 | 88 | template 89 | void PrintSequence(std::ostream& out, Iter begin, Iter end); 90 | 91 | } 92 | 93 | #define OUTPUT_TWO_ARG_CONTAINER(Sequence) \ 94 | template \ 95 | inline std::ostream& operator<<(std::ostream& out, \ 96 | const Sequence& seq) { \ 97 | google::PrintSequence(out, seq.begin(), seq.end()); \ 98 | return out; \ 99 | } 100 | 101 | OUTPUT_TWO_ARG_CONTAINER(std::vector) 102 | OUTPUT_TWO_ARG_CONTAINER(std::deque) 103 | OUTPUT_TWO_ARG_CONTAINER(std::list) 104 | #ifdef GLOG_STL_LOGGING_FOR_EXT_SLIST 105 | OUTPUT_TWO_ARG_CONTAINER(__gnu_cxx::slist) 106 | #endif 107 | 108 | #undef OUTPUT_TWO_ARG_CONTAINER 109 | 110 | #define OUTPUT_THREE_ARG_CONTAINER(Sequence) \ 111 | template \ 112 | inline std::ostream& operator<<(std::ostream& out, \ 113 | const Sequence& seq) { \ 114 | google::PrintSequence(out, seq.begin(), seq.end()); \ 115 | return out; \ 116 | } 117 | 118 | OUTPUT_THREE_ARG_CONTAINER(std::set) 119 | OUTPUT_THREE_ARG_CONTAINER(std::multiset) 120 | 121 | #undef OUTPUT_THREE_ARG_CONTAINER 122 | 123 | #define OUTPUT_FOUR_ARG_CONTAINER(Sequence) \ 124 | template \ 125 | inline std::ostream& operator<<(std::ostream& out, \ 126 | const Sequence& seq) { \ 127 | google::PrintSequence(out, seq.begin(), seq.end()); \ 128 | return out; \ 129 | } 130 | 131 | OUTPUT_FOUR_ARG_CONTAINER(std::map) 132 | OUTPUT_FOUR_ARG_CONTAINER(std::multimap) 133 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED 134 | OUTPUT_FOUR_ARG_CONTAINER(std::unordered_set) 135 | OUTPUT_FOUR_ARG_CONTAINER(std::unordered_multiset) 136 | #endif 137 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED 138 | OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_set) 139 | OUTPUT_FOUR_ARG_CONTAINER(std::tr1::unordered_multiset) 140 | #endif 141 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH 142 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_set) 143 | OUTPUT_FOUR_ARG_CONTAINER(__gnu_cxx::hash_multiset) 144 | #endif 145 | 146 | #undef OUTPUT_FOUR_ARG_CONTAINER 147 | 148 | #define OUTPUT_FIVE_ARG_CONTAINER(Sequence) \ 149 | template \ 150 | inline std::ostream& operator<<(std::ostream& out, \ 151 | const Sequence& seq) { \ 152 | google::PrintSequence(out, seq.begin(), seq.end()); \ 153 | return out; \ 154 | } 155 | 156 | #ifdef GLOG_STL_LOGGING_FOR_UNORDERED 157 | OUTPUT_FIVE_ARG_CONTAINER(std::unordered_map) 158 | OUTPUT_FIVE_ARG_CONTAINER(std::unordered_multimap) 159 | #endif 160 | #ifdef GLOG_STL_LOGGING_FOR_TR1_UNORDERED 161 | OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_map) 162 | OUTPUT_FIVE_ARG_CONTAINER(std::tr1::unordered_multimap) 163 | #endif 164 | #ifdef GLOG_STL_LOGGING_FOR_EXT_HASH 165 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_map) 166 | OUTPUT_FIVE_ARG_CONTAINER(__gnu_cxx::hash_multimap) 167 | #endif 168 | 169 | #undef OUTPUT_FIVE_ARG_CONTAINER 170 | 171 | template 172 | inline std::ostream& operator<<(std::ostream& out, 173 | const std::pair& p) { 174 | out << '(' << p.first << ", " << p.second << ')'; 175 | return out; 176 | } 177 | 178 | namespace google { 179 | 180 | template 181 | inline void PrintSequence(std::ostream& out, Iter begin, Iter end) { 182 | // Output at most 100 elements -- appropriate if used for logging. 183 | for (int i = 0; begin != end && i < 100; ++i, ++begin) { 184 | if (i > 0) out << ' '; 185 | out << *begin; 186 | } 187 | if (begin != end) { 188 | out << " ..."; 189 | } 190 | } 191 | 192 | } 193 | 194 | // Note that this is technically undefined behavior! We are adding things into 195 | // the std namespace for a reason though -- we are providing new operations on 196 | // types which are themselves defined with this namespace. Without this, these 197 | // operator overloads cannot be found via ADL. If these definitions are not 198 | // found via ADL, they must be #included before they're used, which requires 199 | // this header to be included before apparently independent other headers. 200 | // 201 | // For example, base/logging.h defines various template functions to implement 202 | // CHECK_EQ(x, y) and stream x and y into the log in the event the check fails. 203 | // It does so via the function template MakeCheckOpValueString: 204 | // template 205 | // void MakeCheckOpValueString(strstream* ss, const T& v) { 206 | // (*ss) << v; 207 | // } 208 | // Because 'glog/logging.h' is included before 'glog/stl_logging.h', 209 | // subsequent CHECK_EQ(v1, v2) for vector<...> typed variable v1 and v2 can only 210 | // find these operator definitions via ADL. 211 | // 212 | // Even this solution has problems -- it may pull unintended operators into the 213 | // namespace as well, allowing them to also be found via ADL, and creating code 214 | // that only works with a particular order of includes. Long term, we need to 215 | // move all of the *definitions* into namespace std, bet we need to ensure no 216 | // one references them first. This lets us take that step. We cannot define them 217 | // in both because that would create ambiguous overloads when both are found. 218 | namespace std { using ::operator<<; } 219 | 220 | #endif // UTIL_GTL_STL_LOGGING_INL_H_ 221 | -------------------------------------------------------------------------------- /third party/glog/lib/win32/glog.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/third party/glog/lib/win32/glog.lib -------------------------------------------------------------------------------- /third party/glog/lib/win32/glogd.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/third party/glog/lib/win32/glogd.lib -------------------------------------------------------------------------------- /translation/qtt_en.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/translation/qtt_en.qm -------------------------------------------------------------------------------- /translation/qtt_en.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | snappit 6 | 7 | 8 | snappit 9 | 10 | 11 | 12 | 13 | 常规 14 | General 15 | 16 | 17 | 18 | 打开 19 | Open Image 20 | 21 | 22 | 23 | 截屏 24 | Screenshot 25 | 26 | 27 | 28 | 配置 29 | Settings 30 | 31 | 32 | 33 | 语言: 34 | Language: 35 | 36 | 37 | 38 | 39 | Preference 40 | Preference 41 | 42 | 43 | 44 | 45 | Quit 46 | Quit 47 | 48 | 49 | 50 | Choose Image 51 | Choose Image 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /translation/qtt_zh.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZypherChan/ScreenShot/22ad6f5c874c446e35c2176a4504688861e2bc0a/translation/qtt_zh.qm -------------------------------------------------------------------------------- /translation/qtt_zh.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | snappit 6 | 7 | 8 | snappit 9 | 10 | 11 | 12 | 13 | 常规 14 | 常规 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 | Preference 40 | 首选项 41 | 42 | 43 | 44 | 45 | Quit 46 | 退出 47 | 48 | 49 | 50 | Choose Image 51 | 选择图片 52 | 53 | 54 | 55 | --------------------------------------------------------------------------------