예제 #1
0
void ViewStyleStandardPixmap::drawImpl(QPainter* painter, const GuiContext& ctx, const CacheContext& cache, bool* /*showTooltip*/) const
{
    auto style = ctx.style();

    QStyleOption option;
    ctx.initStyleOption(option);

    // dont initialize styleObject from widget for QWindowsVistaStyle
    // this disables buggous animations
    if (style->inherits("QWindowsVistaStyle"))
        option.styleObject = nullptr;

    option.state |= m_pushableTracker.styleStateByItem(cache.id);
    option.rect = cache.cacheView.rect();

    // draw button
    QIcon standardIcon = style->standardIcon(m_standardPixmap, &option, ctx.widget);
    QIcon::Mode mode = QIcon::Disabled;
    if (option.state & QStyle::State_Enabled)
        mode = QIcon::Normal;
    if (option.state & QStyle::State_Selected)
        mode = QIcon::Selected;
    if (option.state & QStyle::State_MouseOver)
        mode = QIcon::Active;

    standardIcon.paint(painter, option.rect, Qt::AlignCenter, mode);
}
예제 #2
0
unsigned int* CIconHandler::GetStandardTexture()
{
	if(!standardTextureGenerated){
		unsigned char si[128*128*4];
		for(int y=0;y<128;++y){
			for(int x=0;x<128;++x){
				float r=sqrtf((y-64)*(y-64)+(x-64)*(x-64))/64.0f;
				if(r>1){
					si[(y*128+x)*4+0]=0;
					si[(y*128+x)*4+1]=0;
					si[(y*128+x)*4+2]=0;
					si[(y*128+x)*4+3]=0;
				} else {
					si[(y*128+x)*4+0]=(unsigned char)(255-r*r*r*255);
					si[(y*128+x)*4+1]=(unsigned char)(255-r*r*r*255);
					si[(y*128+x)*4+2]=(unsigned char)(255-r*r*r*255);
					si[(y*128+x)*4+3]=255;
				}
			}
		}
		CBitmap standardIcon(si,128,128);
		standardTexture=standardIcon.CreateTexture(false);
		standardTextureGenerated=true;

		glBindTexture(GL_TEXTURE_2D, standardTexture);
		if (GLEW_EXT_texture_edge_clamp) {
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		} else {
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		}
	}
	return &standardTexture;
}
예제 #3
0
QSize ViewStyleStandardPixmap::sizeImpl(const GuiContext& ctx, ID /*id*/, ViewSizeMode /*sizeMode*/) const
{
    auto style = ctx.style();
    QIcon standardIcon = style->standardIcon(m_standardPixmap, nullptr, ctx.widget);
    auto sizes = standardIcon.availableSizes();
    if (sizes.isEmpty())
        return QSize(0, 0);

    return sizes.front();
}
PreviewWarningDialog::PreviewWarningDialog(QWidget *parent)
  : QDialog{parent}
  , ui{new Ui::PreviewWarningDialog}
{
  // Setup UI controls.
  ui->setupUi(this);

  auto style    = QApplication::style();
  auto iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize);

  ui->iconLabel->setPixmap(style->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(iconSize, iconSize));
}
예제 #5
0
QRubyMessageBox::QRubyMessageBox(const QString &caption, const QString &text, Icon icon, int button0, int button1, int button2, QWidget *parent, Qt::WFlags f) : QDialog(parent)
{
	mButton0 = 0; mButton1 = 0; mButton2 = 0;

	// Set the dialog caption
	setWindowTitle(caption);

	// Setup the layout
	mDialogLayout = new QVBoxLayout(this);
	mMessageLayout = new QHBoxLayout;
	mDialogLayout->addLayout(mMessageLayout);
	mButtonLayout = new QHBoxLayout;
	mDialogLayout->addLayout(mButtonLayout);
	mButtonLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));

	// Set the message icon
	mIconType = icon;
	mIcon = new QLabel;
	if(icon > 0 && icon < 5)
		mIcon->setPixmap( standardIcon(icon) );
	mMessageLayout->addWidget(mIcon);

	// Set the message text
	mMessage = new QRubyLabel(text);
	mMessageLayout->addWidget(mMessage);

	// Set our button types/numbers
	mButtonType0 = button0;
	mButtonType1 = button1;
	mButtonType2 = button2;

	// Create our buttons
	switch(button0 & QRubyMessageBox::ButtonMask)
	{
		case QRubyMessageBox::Ok:
			mButton0 = new QPushButton(tr("&OK"));
			break;
		case QRubyMessageBox::Cancel:
			mButton0 = new QPushButton(tr("&Cancel"));
			break;
		case QRubyMessageBox::Yes:
			mButton0 = new QPushButton(tr("&Yes"));
			break;
		case QRubyMessageBox::No:
			mButton0 = new QPushButton(tr("&No"));
			break;
		case QRubyMessageBox::Abort:
			mButton0 = new QPushButton(tr("&Abort"));
			break;
		case QRubyMessageBox::Retry:
			mButton0 = new QPushButton(tr("&Retry"));
			break;
		case QRubyMessageBox::Ignore:
			mButton0 = new QPushButton(tr("&Ignore"));
			break;
		case QRubyMessageBox::YesAll:
			mButton0 = new QPushButton(tr("&Yes to all"));
			break;
		case QRubyMessageBox::NoAll:
			mButton0 = new QPushButton(tr("&No to all"));
			break;
		default:
			mButton0 = new QPushButton;
			mButton0->hide();
			break;
	}

	Q_ASSERT(mButton0);

	if(button0 & QRubyMessageBox::FlagMask == QRubyMessageBox::Escape)
		mButton0->setShortcut( QKeySequence(Qt::Key_Escape) );

	if(button0 & QRubyMessageBox::FlagMask == QRubyMessageBox::Default)
		mButton0->setDefault(true);

	connect(mButton0, SIGNAL(clicked()), this, SLOT(buttonClicked()));

	mButtonLayout->addWidget(mButton0);

	mButtonLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));

	setFixedSize (sizeHint());
};
예제 #6
0
void QRubyMessageBox::setIcon(Icon icon)
{
	Q_ASSERT(mIcon);

	mIcon->setPixmap( standardIcon(icon) );
};
예제 #7
0
void WCToolbarManager::ParseManifest(const std::string &manifest, const std::string &directory, const bool &verbose) {
	//Create xml parser
	xercesc::XercesDOMParser* parser = new xercesc::XercesDOMParser();
	//Set validation scheme
	parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);    
	xercesc::ErrorHandler* errHandler = (xercesc::ErrorHandler*) new xercesc::HandlerBase();
	parser->setErrorHandler(errHandler);

	//Get the full path to the manifest
	std::string fullPath = directory + "/" + manifest;
	const char* xmlFile = fullPath.c_str();
	xercesc::DOMElement *rootElement, *buttonsRoot, *toolbarsRoot, *toolbar;
	xercesc::DOMNode *tmpNode;
	xercesc::DOMNodeList *list, *buttonsList;
	xercesc::DOMNamedNodeMap *nodeMap;
	XMLCh* xmlString;
	WCToolbarButton *newButton = NULL;
	WCToolbar *newToolbar = NULL;

	//Try to parse
	try {
		//Parse the manifest
		parser->parse(xmlFile);
		//Get the root document node
		rootElement = parser->getDocument()->getDocumentElement();

		//Find all button child nodes
		xmlString = xercesc::XMLString::transcode("buttons");
		buttonsList = rootElement->getElementsByTagName(xmlString);
		xercesc::XMLString::release(&xmlString);
		buttonsRoot = (xercesc::DOMElement*)buttonsList->item(0);
		xmlString = xercesc::XMLString::transcode("button");
		buttonsList = buttonsRoot->getElementsByTagName(xmlString );
		xercesc::XMLString::release(&xmlString);
		int buttonsCount = buttonsList->getLength();

		XMLCh* xmlMessage = xercesc::XMLString::transcode("message");
		XMLCh* xmlTooltip = xercesc::XMLString::transcode("tooltip");
		XMLCh* xmlType = xercesc::XMLString::transcode("type");
		XMLCh* xmlStdIcon = xercesc::XMLString::transcode("standardIcon");
		XMLCh* xmlActiveIcon = xercesc::XMLString::transcode("activeIcon");
		XMLCh* xmlActive = xercesc::XMLString::transcode("active");
		XMLCh* xmlEnabled = xercesc::XMLString::transcode("enabled");
		char* chars;

		//Loop through all buttons and create buttons
		for (int index=0; index < buttonsCount; index++) {
			//Get the node at index
			nodeMap = buttonsList->item(index)->getAttributes();

			//Get the message
			tmpNode = nodeMap->getNamedItem(xmlMessage);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			WCUserMessage message(chars);
			xercesc::XMLString::release(&chars);

			//Get the tooltip
			tmpNode = nodeMap->getNamedItem(xmlTooltip);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string tooltip(chars);
			xercesc::XMLString::release(&chars);

			//Get the type
			int type;
			tmpNode = nodeMap->getNamedItem(xmlType);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string typeString(chars);
			xercesc::XMLString::release(&chars);
			if (typeString == "MODE") type = TOOLBARELEMENT_TYPE_MODE;
			else if (typeString == "MOMENTARY") type = TOOLBARELEMENT_TYPE_MOMENTARY;
			else type = TOOLBARELEMENT_TYPE_TOGGLE;

			//Get the standard icon
			tmpNode = nodeMap->getNamedItem(xmlStdIcon);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string standardIcon(chars);
			xercesc::XMLString::release(&chars);

			//Get the active icon
			tmpNode = nodeMap->getNamedItem(xmlActiveIcon);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string activeIcon(chars);
			xercesc::XMLString::release(&chars);

			//Get the active state
			bool active = false;
			tmpNode = nodeMap->getNamedItem(xmlActive);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string activeString(chars);
			xercesc::XMLString::release(&chars);
			if (activeString == "true") active = true;

			//Get the enabled state
			bool enabled = false;
			tmpNode = nodeMap->getNamedItem(xmlEnabled);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string enabledString(chars);
			xercesc::XMLString::release(&chars);
			if (enabledString == "true") enabled = true;
			//Create the new toolbar button
			newButton = new WCToolbarButton(message, tooltip, type, standardIcon, activeIcon, active, enabled);
			//Be verbose if appropriate
			if ((newButton != NULL) && verbose) 
				CLOGGER_DEBUG(WCLogManager::RootLogger(), "Button " << message << " successfully loaded");
			//Add object into map
			this->_buttonMap.insert( std::make_pair(message, newButton) );
		}
		//Clean up a bit
		xercesc::XMLString::release(&xmlMessage);
		xercesc::XMLString::release(&xmlTooltip);
		xercesc::XMLString::release(&xmlType);
		xercesc::XMLString::release(&xmlStdIcon);
		xercesc::XMLString::release(&xmlActiveIcon);
		xercesc::XMLString::release(&xmlActive);
		xercesc::XMLString::release(&xmlEnabled);

		//Find all toolbar child nodes
		xmlString = xercesc::XMLString::transcode("toolbars");
		list = rootElement->getElementsByTagName(xmlString);
		xercesc::XMLString::release(&xmlString);
		toolbarsRoot = (xercesc::DOMElement*)list->item(0);
		xmlString = xercesc::XMLString::transcode("toolbar");
		list = toolbarsRoot->getElementsByTagName(xmlString);
		xercesc::XMLString::release(&xmlString);

		XMLCh* xmlName = xercesc::XMLString::transcode("name");
		XMLCh* xmlX = xercesc::XMLString::transcode("x");
		XMLCh* xmlY = xercesc::XMLString::transcode("y");
		XMLCh* xmlWidth = xercesc::XMLString::transcode("width");
		XMLCh* xmlHeight = xercesc::XMLString::transcode("height");
		XMLCh* xmlButton = xercesc::XMLString::transcode("button");

		//Loop through all toolbars and create toolbars and add buttons
		int toolbarsCount = list->getLength();
		for (int index=0; index < toolbarsCount; index++) {
			//Get the node at index
			toolbar = (xercesc::DOMElement*)list->item(index);
			nodeMap = toolbar->getAttributes();

			//Get the name
			tmpNode = nodeMap->getNamedItem(xmlName);
			chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
			std::string name(chars);
			xercesc::XMLString::release(&chars);

			//Get the x position
			tmpNode = nodeMap->getNamedItem(xmlX);
			int xPos = xercesc::XMLString::parseInt(tmpNode->getNodeValue());

			//Get the y position
			tmpNode = nodeMap->getNamedItem(xmlY);
			int yPos = xercesc::XMLString::parseInt(tmpNode->getNodeValue());

			//Get the width
			tmpNode = nodeMap->getNamedItem(xmlWidth);
			int width = xercesc::XMLString::parseInt(tmpNode->getNodeValue());

			//Get the height
			tmpNode = nodeMap->getNamedItem(xmlHeight);
			int height = xercesc::XMLString::parseInt(tmpNode->getNodeValue());

			//Create the new toolbar
			newToolbar = new WCToolbar(this->_document, name, WCVector4(xPos, yPos, width, height));
			//Be verbose if appropriate
			if ((newToolbar != NULL) && verbose) 
				CLOGGER_DEBUG(WCLogManager::RootLogger(), "Toolbar " << name << " successfully loaded");
			//Add toolbar into the map
			this->_toolbarMap.insert( std::make_pair(name, newToolbar) );

			//Add buttons to toolbars
			buttonsList = toolbar->getElementsByTagName(xmlButton);
			//Loop through all buttons
			for (unsigned int buttonIndex=0; buttonIndex < buttonsList->getLength(); buttonIndex++) {
				//Get the value node
				tmpNode = buttonsList->item(buttonIndex)->getFirstChild();
				//Find the button
				chars = xercesc::XMLString::transcode(tmpNode->getNodeValue());
				newButton = this->ButtonFromName(chars);
				xercesc::XMLString::release(&chars);
				//Make sure is not null
				if (newButton != NULL) {
					//If not null, add to toolbar
					newToolbar->AddButton(newButton);
				}
				else {
					CLOGGER_ERROR(WCLogManager::RootLogger(), "WCToolbarManager::ParseManifest - Not able to load button");
				}
			}
		}
		//Clean up a bit
		xercesc::XMLString::release(&xmlName);
		xercesc::XMLString::release(&xmlX);
		xercesc::XMLString::release(&xmlY);
		xercesc::XMLString::release(&xmlWidth);
		xercesc::XMLString::release(&xmlHeight);
		xercesc::XMLString::release(&xmlButton);
	}

	//Error checking
	catch (const xercesc::XMLException& toCatch) {
		char* message = xercesc::XMLString::transcode(toCatch.getMessage());
		CLOGGER_ERROR(WCLogManager::RootLogger(), "WCToolbarManager::ParseManifest - Exception message is: \n" << message);
		xercesc::XMLString::release(&message);
	}
	catch (const xercesc::DOMException& toCatch) {
		char* message = xercesc::XMLString::transcode(toCatch.msg);
		CLOGGER_ERROR(WCLogManager::RootLogger(), "WCToolbarManager::ParseManifest - Exception message is: \n" << message);
		xercesc::XMLString::release(&message);
	}
	catch (...) {
		CLOGGER_ERROR(WCLogManager::RootLogger(), "WCToolbarManager::ParseManifest - Unexpected Exception");
	}
	//Clean up
	delete parser;
	delete errHandler;
}