StelMainGraphicsView.cpp   StelMainGraphicsView.cpp 
skipping to change at line 25 skipping to change at line 25
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelMainGraphicsView.hpp" #include "StelMainGraphicsView.hpp"
#include "StelAppGraphicsScene.hpp" #include "StelAppGraphicsScene.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "Projector.hpp" #include "StelProjector.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelScriptMgr.hpp"
#include <QGLFormat> #include <QGLFormat>
#include <QGraphicsView> #include <QGraphicsView>
#include <QGLWidget> #include <QGLWidget>
#include <QResizeEvent> #include <QResizeEvent>
#include <QSettings> #include <QSettings>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
#include <QAction> #include <QAction>
#include <QRegExp>
#include "gui/StelGui.hpp" #include "gui/StelGui.hpp"
// Initialize static variables // Initialize static variables
StelMainGraphicsView* StelMainGraphicsView::singleton = NULL; StelMainGraphicsView* StelMainGraphicsView::singleton = NULL;
StelMainGraphicsView::StelMainGraphicsView(QWidget* parent, int argc, char* StelMainGraphicsView::StelMainGraphicsView(QWidget* parent, int argc, char*
* argv) : QGraphicsView(parent), wasDeinit(false) * argv)
: QGraphicsView(parent),
wasDeinit(false),
flagInvertScreenShotColors(false),
screenShotPrefix("stellarium-"),
screenShotDir("")
{ {
setScene(new QGraphicsScene(this)); // Is this line useful??
//setScene(new QGraphicsScene(this));
// Can't create 2 StelMainWindow instances // Can't create 2 StelMainWindow instances
assert(!singleton); Q_ASSERT(!singleton);
singleton = this; singleton = this;
setObjectName("Mainview"); setObjectName("Mainview");
// Avoid white background at init // Avoid white background at init
setStyleSheet(QString("QGraphicsView {background: #000;}")); setStyleSheet(QString("QGraphicsView {background: #000;}"));
setFrameShape(QFrame::NoFrame); setFrameShape(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// Create an openGL viewport // Create an openGL viewport
QGLFormat glFormat(QGL::StencilBuffer); QGLFormat glFormat(QGL::StencilBuffer);
//glFormat.setSamples(16); //glFormat.setSamples(16);
//glFormat.setSampleBuffers(true); //glFormat.setSampleBuffers(true);
//glFormat.setDirectRendering(false); //glFormat.setDirectRendering(false);
glWidget = new QGLWidget(glFormat, NULL); glWidget = new QGLWidget(glFormat, NULL);
setViewport(glWidget); setViewport(glWidget);
setFocusPolicy(Qt::ClickFocus);
// Create the main instance of stellarium // Create the main instance of stellarium
stelApp = new StelApp(argc, argv); stelApp = new StelApp(argc, argv);
setScene(new StelAppGraphicsScene()); setScene(new StelAppGraphicsScene());
setFocusPolicy(Qt::ClickFocus);
connect(this, SIGNAL(screenshotRequested()), this, SLOT(doScreenshot
()));
} }
StelMainGraphicsView::~StelMainGraphicsView() StelMainGraphicsView::~StelMainGraphicsView()
{ {
} }
void StelMainGraphicsView::resizeEvent(QResizeEvent* event) void StelMainGraphicsView::resizeEvent(QResizeEvent* event)
{ {
if (scene()) if (scene())
scene()->setSceneRect(QRect(QPoint(0, 0), event->size())); scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
QGraphicsView::resizeEvent(event); QGraphicsView::resizeEvent(event);
} }
void StelMainGraphicsView::init() void StelMainGraphicsView::init()
{ {
//setAutoFillBackground(false); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf);
flagInvertScreenShotColors = conf->value("main/invert_screenshots_co
lors", false).toBool();
// This apparently useless line fixes the scrolling bug // This apparently useless line fixes the scrolling bug
// I suspect a Qt 4.4 bug -> Fixed with Qt 4.4.1 // I suspect a Qt 4.4 bug -> Fixed with Qt 4.4.1
#if QT_VERSION == 0x040400 #if QT_VERSION == 0x040400
setMatrix(QMatrix(1,0,0,1,0.00000001,0)); setMatrix(QMatrix(1,0,0,1,0.00000001,0));
#endif #endif
// Bug in the Qt 4.5 beta version
#if QT_VERSION == 0x040500
setMatrix(QMatrix(1,0,0,1,0.00000001,0));
#endif
// Antialiasing works only with SampleBuffer, but it's much slower // Antialiasing works only with SampleBuffer, but it's much slower
// setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTra nsform | QPainter::HighQualityAntialiasing); // setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTra nsform | QPainter::HighQualityAntialiasing);
//setRenderHint(QPainter::TextAntialiasing, false); //setRenderHint(QPainter::TextAntialiasing, false);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
stelApp->init(); stelApp->init();
static_cast<StelAppGraphicsScene*>(scene())->init(); static_cast<StelAppGraphicsScene*>(scene())->init();
setFocus(); setFocus();
skipping to change at line 115 skipping to change at line 132
setViewportUpdateMode(QGraphicsView::NoViewportUpdate); setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
//setOptimizationFlags(QGraphicsView::DontClipPainter|QGraphicsView: :DontSavePainterState|QGraphicsView::DontAdjustForAntialiasing); //setOptimizationFlags(QGraphicsView::DontClipPainter|QGraphicsView: :DontSavePainterState|QGraphicsView::DontAdjustForAntialiasing);
StelGui* newGui = new StelGui(); StelGui* newGui = new StelGui();
newGui->init(); newGui->init();
StelApp::getInstance().getModuleMgr().registerModule(newGui, true); StelApp::getInstance().getModuleMgr().registerModule(newGui, true);
stelApp->initPlugIns(); stelApp->initPlugIns();
stelApp->getScriptMgr().runScript(stelApp->getStartupScript());
QThread::currentThread()->setPriority(QThread::HighestPriority); QThread::currentThread()->setPriority(QThread::HighestPriority);
} }
//! Delete openGL textures (to call before the GLContext disappears) //! Delete openGL textures (to call before the GLContext disappears)
void StelMainGraphicsView::deinitGL() void StelMainGraphicsView::deinitGL()
{ {
// Can be called only once // Can be called only once
if (wasDeinit==true) if (wasDeinit==true)
return; return;
wasDeinit = true; wasDeinit = true;
StelApp::getInstance().getModuleMgr().unloadAllPlugins(); StelApp::getInstance().getModuleMgr().unloadAllPlugins();
StelApp::getInstance().getModuleMgr().unloadModule("StelGui"); StelApp::getInstance().getModuleMgr().unloadModule("StelGui");
QCoreApplication::processEvents(); QCoreApplication::processEvents();
StelApp* stelApp = &StelApp::getInstance(); StelApp* stelApp = &StelApp::getInstance();
delete stelApp; delete stelApp;
} }
void StelMainGraphicsView::saveScreenShot(const QString& filePrefix, const void StelMainGraphicsView::saveScreenShot(const QString& filePrefix, const
QString& saveDir) const QString& saveDir)
{
screenShotPrefix = filePrefix;
screenShotDir = saveDir;
emit(screenshotRequested());
}
void StelMainGraphicsView::doScreenshot(void)
{ {
QString shotDir; QString shotDir;
QImage im = glWidget->grabFrameBuffer(); QImage im = glWidget->grabFrameBuffer();
if (flagInvertScreenShotColors)
im.invertPixels();
if (saveDir == "") if (screenShotDir == "")
{ {
try try
{ {
shotDir = StelApp::getInstance().getFileMgr().getScr eenshotDir(); shotDir = StelApp::getInstance().getFileMgr().getScr eenshotDir();
if (!StelApp::getInstance().getFileMgr().isWritable( shotDir)) if (!StelApp::getInstance().getFileMgr().isWritable( shotDir))
{ {
qWarning() << "ERROR StelAppSdl::saveScreenS hot: screenshot directory is not writable: " << qPrintable(shotDir); qWarning() << "ERROR StelMainGraphicsView::s aveScreenShot: screenshot directory is not writable: " << qPrintable(shotDi r);
return; return;
} }
} }
catch(std::exception& e) catch(std::runtime_error& e)
{ {
qWarning() << "ERROR StelAppSdl::saveScreenShot: cou ld not determine screenshot directory: " << e.what(); qWarning() << "ERROR StelMainGraphicsView::saveScree nShot: could not determine screenshot directory: " << e.what();
return; return;
} }
} }
else else
{ {
shotDir = saveDir; shotDir = screenShotDir;
} }
QString shotPath; QString shotPath;
for (int j=0; j<100000; ++j) for (int j=0; j<100000; ++j)
{ {
shotPath = shotDir+"/"+filePrefix + QString("%1").arg(j, 3, 10, QLatin1Char('0')) + ".png"; shotPath = shotDir+"/"+ screenShotPrefix + QString("%1").arg (j, 3, 10, QLatin1Char('0')) + ".png";
if (!StelApp::getInstance().getFileMgr().exists(shotPath)) if (!StelApp::getInstance().getFileMgr().exists(shotPath))
break; break;
} }
qDebug() << "Saving screenshot in file: " << shotPath; qDebug() << "Saving screenshot in file: " << shotPath;
im.save(shotPath); im.save(shotPath);
if (!StelApp::getInstance().getFileMgr().exists(shotPath))
return;
else
return;
} }
// Add a new progress bar in the lower right corner of the screen. // Add a new progress bar in the lower right corner of the screen.
class QProgressBar* StelMainGraphicsView::addProgessBar() class QProgressBar* StelMainGraphicsView::addProgressBar()
{ {
StelGui* gui = (StelGui*)GETSTELMODULE("StelGui"); StelGui* gui = (StelGui*)GETSTELMODULE("StelGui");
return gui->addProgessBar(); return gui->addProgressBar();
} }
//! Activate all the QActions associated to the widget //! Activate all the QActions associated to the widget
void StelMainGraphicsView::activateKeyActions(bool b) void StelMainGraphicsView::activateKeyActions(bool b)
{ {
QList<QAction*> aList = findChildren<QAction*>("actionQuit"); QList<QAction*> globalActions = findChildren<QAction*>(QRegExp("acti
QAction* actionQuit = aList.size() > 0 ? aList.at(0) : NULL; on.*_Global"));
if (b==false) if (b==false)
{ {
foreach (QAction* a, actions()) foreach (QAction* a, actions())
{ {
// Special case for the Quit action shortcut which i // Special case for key actions which are named Glob
s always valid al
if (a!=actionQuit) if (!globalActions.contains(a))
removeAction(a); removeAction(a);
} }
} }
else else
{ {
foreach (QAction* a, findChildren<QAction*>()) foreach (QAction* a, findChildren<QAction*>())
{ {
// Special case for the Quit action shortcut which i // Special case for key actions which are named Glob
s always valid al
if (a!=actionQuit) if (!globalActions.contains(a))
addAction(a); addAction(a);
} }
} }
} }
 End of changes. 25 change blocks. 
26 lines changed or deleted 60 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/