$search
00001 /********************************************************************* 00002 * 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2011, Robert Bosch LLC. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Robert Bosch nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 *********************************************************************/ 00036 #include <QtGui/QtGui> 00037 #include <QtOpenGL/QGLWidget> 00038 00039 #include "vlr/display.h" 00040 00041 namespace vlr { 00042 00043 class ToolBar : public QToolBar { 00044 public: 00045 ToolBar(QWidget* parent=NULL) : QToolBar(parent) {} 00046 ~ToolBar() {} 00047 00048 void paintEvent(QPaintEvent *) { 00049 QPainter p(this); 00050 // p.setRenderHint(QPainter::Antialiasing); 00051 p.setBackgroundMode(Qt::TransparentMode); 00052 // p.fillRect(rect(), QColor(0x00FF00A0)); 00053 00054 p.save(); 00055 00056 // extern void render_qt_text(QPainter *, int32_t, int32_t, const QColor &); 00057 // render_qt_text(&p, width(), height(), fgColorForName(color)); 00058 00059 p.restore(); 00060 } 00061 }; 00062 00063 class ToolButton : public QToolButton { 00064 public: 00065 ToolButton(QWidget* parent=NULL) : QToolButton(parent) {} 00066 ~ToolButton() {} 00067 00068 void paintEvent(QPaintEvent *) { 00069 QPainter p(this); 00070 // p.setRenderHint(QPainter::Antialiasing); 00071 p.fillRect(rect(), QColor(0x00FF00A0)); 00072 00073 p.save(); 00074 00075 // extern void render_qt_text(QPainter *, int32_t, int32_t, const QColor &); 00076 // render_qt_text(&p, width(), height(), fgColorForName(color)); 00077 00078 p.restore(); 00079 } 00080 }; 00081 00082 00083 Display::Display(QWidget* parent) : QWidget(parent), glWidget_(NULL) { 00084 create(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_MODE, DEFAULT_HPOS, DEFAULT_VPOS, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00085 glWidget_->requestRedraw(); 00086 } 00087 00088 Display::Display(uint32_t width, uint32_t height) : QWidget(NULL), glWidget_(NULL) { 00089 create(width, height, DEFAULT_MODE, DEFAULT_HPOS, DEFAULT_VPOS, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00090 glWidget_->requestRedraw(); 00091 } 00092 00093 Display::Display(uint32_t width, uint32_t height, int32_t hPos, int32_t vPos) : QWidget(NULL), glWidget_(NULL) { 00094 create(width, height, DEFAULT_MODE, hPos, vPos, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00095 glWidget_->requestRedraw(); 00096 } 00097 00098 Display::Display(uint32_t width, uint32_t height, int32_t hPos, int32_t vPos, QWidget* parent) : 00099 QWidget(parent), glWidget_(NULL) { 00100 create(width, height, DEFAULT_MODE, hPos, vPos, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00101 glWidget_->requestRedraw(); 00102 } 00103 00104 Display::Display(uint32_t width, uint32_t height, displayMode_t mode, int32_t hPos, int32_t vPos, 00105 double frameRate, QWidget* parent, QGLFormat glFormat) : 00106 QWidget(parent), glWidget_(NULL) { 00107 create(width, height, mode, hPos, vPos, frameRate, glFormat); 00108 glWidget_->requestRedraw(); 00109 } 00110 00111 Display::Display(ImageBase& img) : QWidget(NULL), glWidget_(NULL) { 00112 create(img.width(), img.height(), DEFAULT_MODE, DEFAULT_HPOS, DEFAULT_VPOS, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00113 glWidget_->updateImage(img); 00114 } 00115 00116 Display::Display(ImageBase& img, int32_t hPos, int32_t vPos) : QWidget(NULL), glWidget_(NULL) { 00117 create(img.width(), img.height(), DEFAULT_MODE, hPos, vPos, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00118 glWidget_->updateImage(img); 00119 } 00120 00121 Display::Display(ImageBase& img, int32_t hPos, int32_t vPos, QWidget* parent) : QWidget(parent), glWidget_(NULL) { 00122 create(img.width(), img.height(), DEFAULT_MODE, hPos, vPos, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00123 glWidget_->updateImage(img); 00124 } 00125 00126 Display::Display(ImageBase& img, displayMode_t mode, int32_t hPos, int32_t vPos, double frameRate, 00127 QWidget* parent, QGLFormat glFormat) : 00128 QWidget(parent), glWidget_(NULL) { 00129 create(img.width(), img.height(), mode, hPos, vPos, frameRate, glFormat); 00130 glWidget_->updateImage(img); 00131 } 00132 00133 Display::Display(QWidget* parent, int32_t hPos, int32_t vPos) : QWidget(parent), glWidget_(NULL) { 00134 create(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_MODE, DEFAULT_HPOS, DEFAULT_VPOS, DEFAULT_FRAMERATE, DEFAULT_FORMAT); 00135 glWidget_->requestRedraw(); 00136 00137 if (hPos >= 0 && vPos >= 0) { 00138 move(hPos, vPos); 00139 } 00140 } 00141 00142 Display::~Display() { 00143 if(glWidget_) {delete glWidget_;} 00144 } 00145 00146 void Display::create(uint32_t width, uint32_t height, displayMode_t mode, int32_t hPos, int32_t vPos, 00147 double frameRate, QGLFormat glFormat) { 00148 00149 if(thread() != QApplication::instance()->thread()) { 00150 throw VLRException("Display was not created from GUI thread."); 00151 } 00152 00153 if (hPos >= 0 && vPos >= 0) { 00154 move(hPos, vPos); 00155 } 00156 00157 if(width == 1 || height == 1) { 00158 width=DisplayGL::initial_1d_width; 00159 height=DisplayGL::initial_1d_height; 00160 } 00161 setBaseSize(width, height); 00162 QWidget::resize(width, height); 00163 00164 gridLayout = NULL; 00165 // gridLayout = new QGridLayout(this); 00166 00167 glWidget_ = new DisplayGL(this, mode, frameRate, glFormat); 00168 00169 glWidget_->resize(width, height); 00170 // gridLayout->setContentsMargins(0, 0, 0, 0); 00171 // gridLayout->addWidget(glWidget_); 00172 00173 // QToolBar* toolbar = new ToolBar(this); 00174 // 00175 // QAction* action_2d = new QAction("2D", NULL); 00176 // QAction* action_3d = new QAction("3D", NULL); 00177 00178 // ToolButton* tbutton_2d = new ToolButton(NULL); 00179 // toolbar->addWidget(tbutton_2d); 00180 00181 // toolbar->addAction(action_2d); 00182 // toolbar->addAction(action_3d); 00183 // toolbar->setFloatable(true); 00184 // toolbar->setMovable(true); 00185 // toolbar->setIconSize(QSize(16,12)); 00186 // action_2d->connect(action_2d, SIGNAL(activated()), this, SLOT(on_action_2d_activated())); 00187 // action_3d->connect(action_3d, SIGNAL(activated()), this, SLOT(on_action_3d_activated())); 00188 00189 // QButtonGroup* buttons_ = new QButtonGroup(gridLayout); 00190 // gridLayout->addWidget((QWidget*)buttons_); 00191 // addToolBar(Qt::TopToolBarArea, toolbar); 00192 glWidget_->setFocus(); 00193 00194 // raise(); 00195 // show(); 00196 } 00197 00198 void Display::on_action_2d_activated() { 00199 setDisplayMode(MODE_2D); 00200 glWidget_->requestRedraw(); 00201 } 00202 00203 void Display::on_action_3d_activated() { 00204 setDisplayMode(MODE_3D); 00205 glWidget_->requestRedraw(); 00206 } 00207 00208 void Display::setCustomGLDisplay(DisplayGL* customGLWidget) { 00209 00210 if(!customGLWidget) 00211 {throw("zero pointer to custom GL widget.");} 00212 00213 if(glWidget_) {delete glWidget_;} 00214 if(gridLayout) {delete gridLayout;} 00215 00216 glWidget_=customGLWidget; 00217 00218 glWidget_->resize(width(), height()); 00219 00220 glWidget_->setFocus(); 00221 glWidget_->setParent(this); 00222 glWidget_->show(); 00223 setContentsMargins(0, 0, 0, 0); 00224 } 00225 00226 void Display::show() { 00227 raise(); 00228 QWidget::show(); 00229 } 00230 00231 } // namespace vlr