Exemplo n.º 1
0
void GraphicsView::setupContextMenu() {

	// Get the last modification date
	qint64 secs = QFileInfo(QDir::homePath() + "/.photoqt/contextmenu").lastModified().toMSecsSinceEpoch();

	// If the menu has been modified since last time or hasn't been setup yet, we set it up
	if(secs != menuLastChange || !menuSetup) {

		menuSetup = true;
		menuLastChange = secs;

		// Make sure it's empty (after a change, we would re-setup the menu and not calling clear() would lead to double entries)
		menu->clear();


		// Move in directory
		QWidgetAction *moveImg = new QWidgetAction(menu);
		CustomLabel *move = new CustomLabel(tr("Move:"));
		move->setStyleSheet("QLabel {color: rgba(180,180,180,255); background: transparent; }");
		CustomLabel *moveFirst = new CustomLabel;
		moveFirst->setPixmap(QPixmap(":/img/firstSmall.png"));
		moveFirst->setObjectName("__CTX__movefirst");
		moveFirst->setCursor(Qt::PointingHandCursor);
		CustomLabel *moveLeft = new CustomLabel(tr("Previous"));
		moveLeft->setObjectName("__CTX__moveprev");
		moveLeft->setCursor(Qt::PointingHandCursor);
		CustomLabel *moveRight = new CustomLabel(tr("Next"));
		moveRight->setObjectName("__CTX__movenext");
		moveRight->setCursor(Qt::PointingHandCursor);
		CustomLabel *moveLast = new CustomLabel;
		moveLast->setPixmap(QPixmap(":/img/lastSmall.png"));
		moveLast->setObjectName("__CTX__movelast");
		moveLast->setCursor(Qt::PointingHandCursor);
		QWidget *moveWid = new QWidget;
		QHBoxLayout *moveLay = new QHBoxLayout;
		moveLay->addWidget(move);
		moveLay->addSpacing(5);
		moveLay->addWidget(moveFirst);
		moveLay->addSpacing(5);
		moveLay->addWidget(moveLeft);
		moveLay->addWidget(moveRight);
		moveLay->addSpacing(5);
		moveLay->addWidget(moveLast);
		moveLay->addStretch();
		moveWid->setLayout(moveLay);
		moveImg->setDefaultWidget(moveWid);
		menu->addAction(moveImg);
		connect(moveFirst, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(moveLeft, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(moveRight, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(moveLast, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));

		// Rotate Image
		QWidgetAction *rotateImg = new QWidgetAction(menu);
		CustomLabel *rot = new CustomLabel(tr("Rotate:"));
		rot->setStyleSheet("QLabel {color: rgba(180,180,180,255); background: transparent; }");
		CustomLabel *rotLeft = new CustomLabel("<img src=\":/img/rotateLeftSmall.png\"> " + tr("Left"));
		rotLeft->setObjectName("__CTX__rotateleft");
		rotLeft->setCursor(Qt::PointingHandCursor);
		CustomLabel *rotRight = new CustomLabel(tr("Right") + " <img src=\":/img/rotateRightSmall.png\">");
		rotRight->setObjectName("__CTX__rotateright");
		rotRight->setCursor(Qt::PointingHandCursor);
		QWidget *rotWid = new QWidget;
		QHBoxLayout *rotLay = new QHBoxLayout;
		rotLay->addWidget(rot);
		rotLay->addSpacing(5);
		rotLay->addWidget(rotLeft);
		rotLay->addSpacing(10);
		rotLay->addWidget(rotRight);
		rotLay->addStretch();
		rotWid->setLayout(rotLay);
		rotateImg->setDefaultWidget(rotWid);
		menu->addAction(rotateImg);
		connect(rotLeft, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(rotRight, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));

		// Flip Image
		QWidgetAction *flipImg = new QWidgetAction(menu);
		CustomLabel *flip = new CustomLabel(tr("Flip:"));
		flip->setStyleSheet("QLabel {color: rgba(180,180,180,255); background: transparent; }");
		CustomLabel *flipHor = new CustomLabel("<img src=\":/img/flipHSmall.png\"> " + tr("Horizontal"));
		flipHor->setObjectName("__CTX__fliph");
		flipHor->setCursor(Qt::PointingHandCursor);
		CustomLabel *flipVer = new CustomLabel("<img src=\":/img/flipVSmall.png\">" + tr("Vertical"));
		flipVer->setObjectName("__CTX__flipv");
		flipVer->setCursor(Qt::PointingHandCursor);
		QWidget *flipWid = new QWidget;
		QHBoxLayout *flipLay = new QHBoxLayout;
		flipLay->addWidget(flip);
		flipLay->addSpacing(5);
		flipLay->addWidget(flipHor);
		flipLay->addSpacing(5);
		flipLay->addWidget(flipVer);
		flipLay->addStretch();
		flipWid->setLayout(flipLay);
		flipImg->setDefaultWidget(flipWid);
		menu->addAction(flipImg);
		connect(flipHor, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(flipVer, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));

		// Zoom Image
		QWidgetAction *zoomImg = new QWidgetAction(menu);
		CustomLabel *zoom = new CustomLabel(tr("Zoom:"));
		zoom->setStyleSheet("QLabel {color: rgba(180,180,180,255); background: transparent; }");
		CustomLabel *zoomIn = new CustomLabel("(+) " + tr("In"));
		zoomIn->setObjectName("__CTX__zoomin");
		zoomIn->setCursor(Qt::PointingHandCursor);
		CustomLabel *zoomOut = new CustomLabel("(-) " + tr("Out"));
		zoomOut->setObjectName("__CTX__zoomout");
		zoomOut->setCursor(Qt::PointingHandCursor);
		CustomLabel *zoomActual = new CustomLabel("(1:1) " + tr("Actual"));
		zoomActual->setObjectName("__CTX__zoomactual");
		zoomActual->setCursor(Qt::PointingHandCursor);
		CustomLabel *zoomReset = new CustomLabel("(0) " + tr("Reset"));
		zoomReset->setObjectName("__CTX__zoomreset");
		zoomReset->setCursor(Qt::PointingHandCursor);
		QWidget *zoomWid = new QWidget;
		QHBoxLayout *zoomLay = new QHBoxLayout;
		zoomLay->addWidget(zoom);
		zoomLay->addSpacing(5);
		zoomLay->addWidget(zoomIn);
		zoomLay->addSpacing(5);
		zoomLay->addWidget(zoomOut);
		zoomLay->addSpacing(5);
		zoomLay->addWidget(zoomActual);
		zoomLay->addSpacing(5);
		zoomLay->addWidget(zoomReset);
		zoomLay->addStretch();
		zoomWid->setLayout(zoomLay);
		zoomImg->setDefaultWidget(zoomWid);
		menu->addAction(zoomImg);
		connect(zoomIn, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(zoomOut, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(zoomActual, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));
		connect(zoomReset, SIGNAL(clicked()), this, SLOT(contextMenuClickedWidgetAction()));

		menu->addSeparator();

		QAction *scale = new QAction(tr("Scale Image"), menu);
		scale->setData("__CTX__scaleimage");
		scale->setIcon(QIcon(":/img/scale.png"));
		menu->addAction(scale);
		connect(scale, SIGNAL(triggered()), this, SLOT(contextMenuClicked()));

		menu->addSeparator();

		QAction *openInFm = new QAction(tr("Open in default File Manager"), menu);
		openInFm->setData("__CTX__openinfm");
		openInFm->setIcon(QIcon(":/img/open.png"));
		menu->addAction(openInFm);
		connect(openInFm, SIGNAL(triggered()), this, SLOT(contextMenuClicked()));

		QAction *deleteFile = new QAction(tr("Delete File"), menu);
		deleteFile->setData("__CTX__delete");
		deleteFile->setIcon(QIcon(":/img/delete.png"));
		menu->addAction(deleteFile);
		connect(deleteFile, SIGNAL(triggered()), this, SLOT(contextMenuClicked()));

		QAction *renameFile = new QAction(tr("Rename File"), menu);
		renameFile->setData("__CTX__rename");
		renameFile->setIcon(QIcon(":/img/rename.png"));
		menu->addAction(renameFile);
		connect(renameFile, SIGNAL(triggered()), this, SLOT(contextMenuClicked()));

		menu->addSeparator();

		// Now read in the additional entries from file
		QFile file(QDir::homePath() + "/.photoqt/contextmenu");

		if(file.open(QIODevice::ReadOnly)) {

			QTextStream in(&file);

			QStringList all = in.readAll().split("\n\n",QString::SkipEmptyParts);

			// And set up the rest of the menu
			for(int i = 0; i < all.length(); ++i) {

				QString cmd = all.at(i).split("\n").at(0);
				QString desc = all.at(i).split("\n").at(1);

				QString binary = cmd;
				binary = binary.remove("%f").remove("%d");

				binary = binary.trimmed();

				QAction *action = new QAction(desc, menu);
				action->setIcon(QIcon::fromTheme(binary));
				action->setData(cmd);
				menu->addAction(action);

				connect(action, SIGNAL(triggered()), this, SLOT(contextMenuClicked()));

			}

		}

	}

}
Exemplo n.º 2
0
AboutQtDialog::AboutQtDialog() : QWidget(NULL)
{
	setWindowTitle(tr("About Qt"));
	StyleStorage::staticStorage(RSR_STORAGE_STYLESHEETS)->insertAutoStyle(this, STS_PLUGINMANAGER_ABOUT_QT);

	CustomBorderContainer *border = CustomBorderStorage::staticStorage(RSR_STORAGE_CUSTOMBORDER)->addBorder(this, CBS_DIALOG);
	if (border)
	{
		border->setAttribute(Qt::WA_DeleteOnClose, true);
		border->setResizable(false);
		border->setMinimizeButtonVisible(false);
		border->setMaximizeButtonVisible(false);
	}
	else
	{
		setAttribute(Qt::WA_DeleteOnClose, true);
		setWindowFlags(Qt::Dialog | Qt::WindowTitleHint);
	}

#ifdef Q_WS_MAC
	setWindowGrowButtonEnabled(this->window(), false);
#endif

	// creating layouts and items
	// main layout
	setLayout(new QVBoxLayout(this));

	layout()->setContentsMargins(8, 18, 8, 6);
	layout()->setSpacing(14);

	// text and icon layout
	QHBoxLayout * textLayout = new QHBoxLayout;
	textLayout->setSpacing(6);
	CustomLabel * icon = new CustomLabel(this);
	IconStorage::staticStorage(RSR_STORAGE_MENUICONS)->insertAutoIcon(icon, MNI_PLUGINMANAGER_ABOUT_QT, 0, 0, "pixmap");
	icon->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
	icon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
	textLayout->addWidget(icon);
	QVBoxLayout * captLayout = new QVBoxLayout;
	captLayout->setSpacing(8);
	CustomLabel * caption = new CustomLabel(this);
	caption->setObjectName("caption");
	caption->setText(tr("About Qt"));

	CustomLabel * text = new CustomLabel(this);
	text->setTextFormat(Qt::RichText);
	text->setWordWrap(true);
	text->setMaximumWidth(350);
	text->setOpenExternalLinks(true);
	text->setObjectName("lblAboutQtText");

	GraphicsEffectsStorage::staticStorage(RSR_STORAGE_GRAPHICSEFFECTS)->installGraphicsEffect(text, GFX_LABELS);
	QString localizedText = tr("<p>This program uses Qt version %1.</p>"
				   "<p>Qt is a C++ toolkit for cross-platform application "
				   "development.</p>"
				   "<p>Qt provides single-source portability across MS&nbsp;Windows, "
				   "Mac&nbsp;OS&nbsp;X, Linux, and all major commercial Unix variants. "
				   "Qt is also available for embedded devices as Qt for Embedded Linux "
				   "and Qt for Windows CE.</p>"
				   "<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the "
				   "development of Qt applications (proprietary or open source) provided "
				   "you can comply with the terms and conditions of the GNU LGPL version "
				   "2.1.</p>"
				   "<p>Please see <a href=\"http://qt.nokia.com/products/licensing\">qt.nokia.com/products/licensing</a> "
				   "for an overview of Qt licensing.</p>"
				   "<p>Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).</p>"
				   "<p>Qt is a Nokia product. See <a href=\"http://qt.nokia.com/\">qt.nokia.com</a> "
				   "for more information.</p>").arg(QLatin1String(QT_VERSION_STR));
	// adding shadow (it's a rich text)
	text->setText(localizedText);
	captLayout->addWidget(caption);
	captLayout->addWidget(text);
	textLayout->addItem(captLayout);

	// button layout
	QHBoxLayout * buttonLayout = new QHBoxLayout;
	buttonLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
	QPushButton * okButton = new QPushButton(this);
	okButton->setDefault(true);
	okButton->setAutoDefault(false);
	okButton->setText(tr("OK"));
	connect(okButton, SIGNAL(clicked()), (parentWidget() ? parentWidget() : this), SLOT(close()));
	buttonLayout->addWidget(okButton);

	layout()->addItem(textLayout);
	layout()->addItem(buttonLayout);
}