void Style::drawComboBox(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { ASSURE_OPTION(cmb, ComboBox); B_STATES if ( widget && widget->inherits("WebView") ) { if (!(config.btn.backLightHover || cmb->editable)) { // paints hardcoded black text bypassing the style?! grrr... QStyleOptionComboBox *_cmb = const_cast<QStyleOptionComboBox*>(cmb); _cmb->palette.setColor(config.btn.std_role[Bg], QColor(230,230,230,255)); _cmb->palette.setColor(config.btn.active_role[Bg], QColor(255,255,255,255)); } widget = 0; } const int f1 = F(1), f2 = F(2); QRect ar; const QComboBox *combo = widget ? qobject_cast<const QComboBox*>(widget) : 0; QColor c = CONF_COLOR(btn.std, Bg); const bool listShown = combo && combo->view() && ((QWidget*)(combo->view()))->isVisible(); if (listShown) // this messes up hover hover = hover || QRect(widget->mapToGlobal(RECT.topLeft()), RECT.size()).contains(QCursor::pos()); if (isEnabled && (cmb->subControls & SC_ComboBoxArrow) && (!combo || combo->count() > 0)) { // do we have an arrow? ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); ar.setBottom(ar.bottom()-f2); } // the frame if ((cmb->subControls & SC_ComboBoxFrame) && cmb->frame) { if (cmb->editable) drawLineEdit(option, painter, widget, false); else { if (!ar.isNull()) { animStep = (appType == GTK || !widget) ? 6*hover : Animator::Hover::step(widget); if (listShown) animStep = 6; int btn_layer = config.btn.layer; Gradients::Type btn_grd = config.btn.gradient; config.btn.round = !config.btn.round; const bool comboNotSmallerThanTool = config.chooser.layer == Raised || config.chooser.layer == Inlay || config.btn.tool.frame == Sunken || config.btn.tool.frame == Relief; if (comboNotSmallerThanTool && widget && qobject_cast<QToolBar*>(widget->parentWidget())) { GRAD(btn) = GRAD(btn.tool); config.btn.layer = config.btn.tool.frame; } else { GRAD(btn) = GRAD(chooser); config.btn.layer = config.chooser.layer; } drawButtonFrame(option, painter, widget, animStep); config.btn.round = !config.btn.round; config.btn.layer = btn_layer; config.btn.gradient = btn_grd; } else shadows.sunken[!config.btn.round][isEnabled].render(RECT, painter); } } // the arrow if (!ar.isNull()) { if (!(ar.width()%2) ) ar.setWidth(ar.width()-1); const int dy = ar.height()/4; QRect rect = ar.adjusted(0, dy, 0, -dy); Navi::Direction dir = Navi::S; bool upDown = false; if (listShown) dir = (config.leftHanded) ? Navi::E : Navi::W; else if (combo) { if (combo->currentIndex() == 0) dir = Navi::S; else if (combo->currentIndex() == combo->count()-1) dir = Navi::N; else upDown = true; } painter->save(); painter->setPen(Qt::NoPen); if (cmb->editable) { if (upDown || dir == Navi::N) dir = Navi::S; upDown = false; // shall never look like spinbox! hover = hover && (cmb->activeSubControls == SC_ComboBoxArrow); if (!sunken) { painter->setBrush(FCOLOR(Base).dark(105)); rect.translate(0, f2); drawArrow(dir, rect, painter); rect.translate(0, -f2); } if (hover || listShown) painter->setBrush(FCOLOR(Highlight)); else painter->setBrush( Colors::mid(FCOLOR(Base), FCOLOR(Text)) ); } else if (config.btn.backLightHover) painter->setBrush(Colors::mid(c, CONF_COLOR(btn.std, Fg), 6-animStep, 3+animStep)); else { c = Colors::mid(c, CONF_COLOR(btn.active, Bg)); c = Colors::mid(c, CONF_COLOR(btn.active, Bg), 6-animStep, animStep); masks.rect[!config.btn.round].render(ar, painter, GRAD(chooser), ori[1], c, RECT.height()-f2, QPoint(0, ar.y() - RECT.y()) ); painter->setBrush(Colors::mid(c, CONF_COLOR(btn.active, Fg), 1,2)); } if (upDown) { rect.setBottom(rect.y() + rect.height()/2); rect.translate(0, -1); drawArrow(Navi::N, rect, painter); rect.translate(0, rect.height()); drawArrow(Navi::S, rect, painter); } else { if (dir == Navi::N) // loooks unbalanced otherwise rect.translate(0, -f1); drawArrow(dir, rect, painter); } painter->restore(); } }
void ScrollZoomWidget::UpdateScrollBarPosition() { QRect scrollBarRect = GetScrollBarRect(); horizontalScrollBar->move(scrollBarRect.x(), scrollBarRect.y()); horizontalScrollBar->resize(scrollBarRect.width(), scrollBarRect.height()); }
void GLWidgetRenderer::drawFrame() { DPTR_D(GLWidgetRenderer); #ifdef QT_OPENGL_ES_2 #define FMT_INTERNAL GL_BGRA //why BGRA? #define FMT GL_BGRA glUseProgram(d.program); //qpainter need glActiveTexture(GL_TEXTURE0); //TODO: can remove?? glUniform1i(d.tex_location, 0); #else //QT_OPENGL_ES_2 #define FMT_INTERNAL GL_RGBA //why? why 3 works? #define FMT GL_BGRA #endif //QT_OPENGL_ES_2 glBindTexture(GL_TEXTURE_2D, d.texture); d.setupQuality(); QRect roi = realROI(); //uploading part of image eats less gpu memory, but may be more cpu(gles) //FIXME: more cpu usage then qpainter. FBO, VBO? #define ROI_TEXCOORDS 1 if (ROI_TEXCOORDS || roi.size() == QSize(d.src_width, d.src_height)) { glTexImage2D(GL_TEXTURE_2D , 0 //level , FMT_INTERNAL //internal format. 4? why GL_RGBA? GL_RGB? , d.src_width, d.src_height , 0 //border, ES not support , FMT //format, must the same as internal format? , GL_UNSIGNED_BYTE , d.data.constData()); } else { #ifdef GL_UNPACK_ROW_LENGTH // http://stackoverflow.com/questions/205522/opengl-subtexturing glPixelStorei(GL_UNPACK_ROW_LENGTH, d.src_width); //glPixelStorei or compute pointer glPixelStorei(GL_UNPACK_SKIP_PIXELS, roi.x()); glPixelStorei(GL_UNPACK_SKIP_ROWS, roi.y()); glTexImage2D(GL_TEXTURE_2D, 0, FMT_INTERNAL, roi.width(), roi.height(), 0, FMT, GL_UNSIGNED_BYTE, d.data.constData()); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); #else // GL ES //define it? or any efficient way? glTexImage2D(GL_TEXTURE_2D, 0, FMT_INTERNAL, roi.width(), roi.height(), 0, FMT, GL_UNSIGNED_BYTE, NULL); // how to use only 1 call? //glTexSubImage2D(GL_TEXTURE_2D, 0, roi.x(), roi.y(), roi.width(), roi.height(), FMT, GL_UNSIGNED_BYTE, d.data.constData()); for(int y = 0; y < roi.height(); y++) { char *row = d.data.data() + ((y + roi.y())*d.src_width + roi.x()) * 4; glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, roi.width(), 1, FMT, GL_UNSIGNED_BYTE, row); } #endif //GL_UNPACK_ROW_LENGTH } //TODO: compute kTexCoords only if roi changed #if ROI_TEXCOORDS const GLfloat kTexCoords[] = { (GLfloat)roi.x()/(GLfloat)d.src_width, (GLfloat)roi.y()/(GLfloat)d.src_height, (GLfloat)(roi.x() + roi.width())/(GLfloat)d.src_width, (GLfloat)roi.y()/(GLfloat)d.src_height, (GLfloat)(roi.x() + roi.width())/(GLfloat)d.src_width, (GLfloat)(roi.y()+roi.height())/(GLfloat)d.src_height, (GLfloat)roi.x()/(GLfloat)d.src_width, (GLfloat)(roi.y()+roi.height())/(GLfloat)d.src_height, }; /// glVertexAttribPointer(d.tex_coords_location, 2, GL_FLOAT, GL_FALSE, 0, kTexCoords); /// glEnableVertexAttribArray(d.tex_coords_location); #else const GLfloat kTexCoords[] = { 0, 0, 1, 0, 1, 1, 0, 1, }; #endif //ROI_TEXCOORDS #ifndef QT_OPENGL_ES_2 //qpainter will reset gl state, so need glMatrixMode and clear color(in drawBackground()) //TODO: study what state will be reset glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); d.setupAspectRatio(); //TODO: can we avoid calling this every time but only in resize event? glVertexPointer(2, GL_FLOAT, 0, kVertices); glEnableClientState(GL_VERTEX_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, kTexCoords); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); #else //QT_OPENGL_ES_2 d.setupAspectRatio(); //TODO: can we avoid calling this every time but only in resize event? //qpainter need. TODO: VBO? glVertexAttribPointer(d.position_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); glEnableVertexAttribArray(d.position_location); glVertexAttribPointer(d.tex_coords_location, 2, GL_FLOAT, GL_FALSE, 0, kTexCoords); glEnableVertexAttribArray(d.tex_coords_location); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableVertexAttribArray(d.tex_coords_location); glDisableVertexAttribArray(d.position_location); #endif //QT_OPENGL_ES_2 }
PyObject* scribus_getproperty(PyObject* /*self*/, PyObject* args, PyObject* kw) { PyObject* objArg = NULL; char* propertyName = NULL; char* kwargs[] = {const_cast<char*>("object"), const_cast<char*>("property"), NULL}; if (!PyArg_ParseTupleAndKeywords(args, kw, "Oes", kwargs, &objArg, "ascii", &propertyName)) return NULL; // Get the QObject* the object argument refers to QObject* obj = getQObjectFromPyArg(objArg); if (!obj) return NULL; objArg = NULL; // no need to decref, it's borrowed // Get the QMetaProperty for the property, so we can check // if it's a set/enum and do name/value translation. const QMetaObject* objmeta = obj->metaObject(); int i = objmeta->indexOfProperty(propertyName); if (i == -1) { PyErr_SetString(PyExc_ValueError, QObject::tr("Property not found").toLocal8Bit().data()); return NULL; } QMetaProperty propmeta = objmeta->property(i); if (!propmeta.isValid()) { PyErr_SetString(PyExc_ValueError, QObject::tr("Invalid property").toLocal8Bit().data()); return NULL; } // Get the property value as a variant type QVariant prop = obj->property(propertyName); // Convert the property to an instance of the closest matching Python type. PyObject* resultobj = NULL; // NUMERIC TYPES if (prop.type() == QVariant::Int) resultobj = PyLong_FromLong(prop.toInt()); else if (prop.type() == QVariant::Double) resultobj = PyFloat_FromDouble(prop.toDouble()); // BOOLEAN else if (prop.type() == QVariant::Bool) resultobj = PyBool_FromLong(prop.toBool()); // STRING TYPES else if (prop.type() == QVariant::ByteArray) resultobj = PyString_FromString(prop.toByteArray().data()); else if (prop.type() == QVariant::String) resultobj = PyString_FromString(prop.toString().toUtf8().data()); // HIGHER ORDER TYPES else if (prop.type() == QVariant::Point) { // Return a QPoint as an (x,y) tuple. QPoint pt = prop.toPoint(); return Py_BuildValue("(ii)", pt.x(), pt.y()); } else if (prop.type() == QVariant::Rect) { // Return a QRect as an (x,y,width,height) tuple. // FIXME: We should really construct and return an object that // matches the API of QRect and has properties to keep // left/top/right/bottom and x/y/width/height in sync. QRect r = prop.toRect(); return Py_BuildValue("(iiii)", r.x(), r.y(), r.width(), r.height()); } else if (prop.type() == QVariant::StringList) { QStringList tmp = prop.toStringList(); return convert_QStringList_to_PyListObject(tmp); } // UNHANDLED TYPE else { PyErr_SetString(PyExc_TypeError, QObject::tr("Couldn't convert result type '%1'.").arg(prop.typeName()).toLocal8Bit().constData() ); return resultobj; } // Return the resulting Python object if (resultobj == NULL) { // An exception was set while assigning to resultobj assert(PyErr_Occurred()); return NULL; } else return resultobj; }
/// XXX void MiamStyle::drawScrollBar(QPainter *p, const QWidget *widget) const { QStyleOptionSlider scrollbar; scrollbar.palette = QApplication::palette(); const QScrollBar *sc = qobject_cast<const QScrollBar *>(widget); scrollbar.initFrom(sc); QRect subLineRect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &scrollbar, QStyle::SC_ScrollBarSubLine, sc); QRect addLineRect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &scrollbar, QStyle::SC_ScrollBarAddLine, sc); QRect sliderRect = QApplication::style()->subControlRect(QStyle::CC_ScrollBar, &scrollbar, QStyle::SC_ScrollBarSlider, sc); //qDebug() << subLineRect << sliderRect << addLineRect; if (sc->orientation() == Qt::Vertical) { subLineRect.adjust(0, 0, -1, 0); addLineRect.adjust(0, 0, -1, 0); sliderRect.adjust(0, 0, -1, 0); } else { subLineRect.adjust(0, 0, 0, -1); addLineRect.adjust(0, 0, 0, -1); sliderRect.adjust(0, 0, 0, -1); } p->setPen(Qt::NoPen); p->setBrush(scrollbar.palette.window()); p->drawRect(sc->rect()); p->setBrush(scrollbar.palette.base().color().darker(125)); p->drawRect(sliderRect); // Highlight p->save(); QPoint pos = sc->mapFromGlobal(QCursor::pos()); p->setPen(scrollbar.palette.highlight().color()); if (!sc->isSliderDown()) { p->setBrush(scrollbar.palette.highlight().color().lighter()); if (subLineRect.contains(pos)) { p->drawRect(subLineRect); } else if (sliderRect.contains(pos)) { p->drawRect(sliderRect); } else if (addLineRect.contains(pos)) { p->drawRect(addLineRect); } } else { p->setBrush(scrollbar.palette.highlight().color()); //if (_isDown == 0) { // p->drawRect(subLineRect); //} else if (_isDown == 1) { // p->drawRect(sliderRect); //} else if (_isDown == 2) { // p->drawRect(addLineRect); //} } p->restore(); // Draw sort indicator static const QPointF upArrow[3] = { QPointF(0.0, 1.0), QPointF(1.0, 0.0), QPointF(2.0, 1.0) }; static const QPointF downArrow[3] = { QPointF(0.0, 0.0), QPointF(2.0, 0.0), QPointF(1.0, 1.0) }; static const QPointF leftArrow[3] = { QPointF(0.0, 1.0), QPointF(1.0, 0.0), QPointF(1.0, 2.0) }; static const QPointF rightArrow[3] = { QPointF(0.0, 0.0), QPointF(1.0, 1.0), QPointF(0.0, 2.0) }; // Arrows p->save(); if (scrollbar.palette.windowText().color().value() < 128) { p->setPen(scrollbar.palette.dark().color()); p->setBrush(scrollbar.palette.dark()); } else { p->setPen(scrollbar.palette.mid().color()); p->setBrush(scrollbar.palette.mid()); } QTransform t; float ratio = (float) subLineRect.height() / 4.0; t.scale(ratio, ratio); if (sc->orientation() == Qt::Vertical) { QPolygonF up, down; up.append(t.map(upArrow[0])); up.append(t.map(upArrow[1])); up.append(t.map(upArrow[2])); down.append(t.map(downArrow[0])); down.append(t.map(downArrow[1])); down.append(t.map(downArrow[2])); p->translate(subLineRect.width() / 4.0, subLineRect.height() / 3.0); p->drawPolygon(up); p->translate(0, addLineRect.y()); p->drawPolygon(down); } else { QPolygonF left, right; left.append(t.map(leftArrow[0])); left.append(t.map(leftArrow[1])); left.append(t.map(leftArrow[2])); right.append(t.map(rightArrow[0])); right.append(t.map(rightArrow[1])); right.append(t.map(rightArrow[2])); p->translate(subLineRect.height() / 3.0, subLineRect.width() / 4.0); p->drawPolygon(left); p->translate(addLineRect.x(), 0); p->drawPolygon(right); } p->restore(); }
QRect QTabContainer::findDropRect(const QPoint& globalPos, int tabWidth, QTabFramework::InsertPolicy& insertPolicy, QRect& tabRectResult, int& tabIndex) { QPoint pos = mapFromGlobal(globalPos); QRect containerRect = rect(); QRect result; tabIndex = -1; if(containerRect.contains(pos)) { if(count() == 0) { insertPolicy = QTabFramework::InsertOnTop; result = containerRect; } else if(tabBar()->geometry().contains(pos)) { insertPolicy = QTabFramework::Insert; result = containerRect; QTabBar* tabBar = this->tabBar(); for(int i = 0, count = tabBar->count(); i < count; ++i) { QRect tabRect = tabBar->tabRect(i); if(tabRect.contains(pos)) { tabRectResult = tabRect; tabRectResult.setRight(tabRect.left() + tabWidth); tabRectResult.translate(tabBar->mapToGlobal(QPoint(0, 0))); tabIndex = i; break; } } } else if(pos.x() < containerRect.x() + containerRect.width() / 3) { insertPolicy = QTabFramework::InsertLeft; result = QRect(containerRect.topLeft(), QPoint(containerRect.x() + containerRect.width() / 3, containerRect.bottom())); } else if(pos.x() >= containerRect.x() + containerRect.width() * 2 / 3) { insertPolicy = QTabFramework::InsertRight; result = QRect(QPoint(containerRect.x() + containerRect.width() * 2 / 3, containerRect.y()), containerRect.bottomRight()); } else if(pos.y() < containerRect.y() + tabBar()->geometry().height()) { insertPolicy = QTabFramework::Insert; result = containerRect; tabIndex = this->tabBar()->count(); } else if(pos.y() < containerRect.y() + containerRect.height() / 3) { insertPolicy = QTabFramework::InsertTop; result = QRect(containerRect.topLeft(), QPoint(containerRect.right(), containerRect.y() + containerRect.height() / 3)); } else if(pos.y() >= containerRect.y() + containerRect.height() * 2 / 3) { insertPolicy = QTabFramework::InsertBottom; result = QRect(QPoint(containerRect.x(), containerRect.y() + containerRect.height() * 2 / 3), containerRect.bottomRight()); } else { insertPolicy = QTabFramework::InsertOnTop; result = containerRect; } } else { insertPolicy = QTabFramework::InsertFloating; return QRect(); } result.translate(mapToGlobal(QPoint(0, 0))); return result; }
void MainWindow::Private::captureCatalog() { qDebug() << "captureCatalog"; //設定確認 checkSavePath(); QRect captureRect = CATALOG_RECT_CAPTURE; QList<QRect> shipRectList; { shipRectList << CATALOG_RECT_SHIP1 << CATALOG_RECT_SHIP2 << CATALOG_RECT_SHIP3; } QList<QRect> pageRectList; { pageRectList << CATALOG_RECT_PAGE1 << CATALOG_RECT_PAGE2 << CATALOG_RECT_PAGE3 << CATALOG_RECT_PAGE4 << CATALOG_RECT_PAGE5; } QImage resultImg(captureRect.width() * shipRectList.size() , captureRect.height() * pageRectList.size() ,QImage::Format_ARGB32); QPainter painter(&resultImg); QPoint currentPos = ui.webView->page()->mainFrame()->scrollPosition(); QRect geometry = ui.webView->getGameRect(); if (GameScreen(ui.webView->capture()).screenType() != GameScreen::CatalogScreen) { ui.webView->page()->mainFrame()->setScrollPosition(currentPos); ui.statusBar->showMessage(tr("not in catalog"), STATUS_BAR_MSG_TIME); return; } //開始確認 QMessageBox::StandardButton res = QMessageBox::warning(q , tr("Kan Memo") , tr("Capture the catalog.\nPlease wait while a cup of coffee.") , QMessageBox::Yes | QMessageBox::Cancel); if(res == QMessageBox::Cancel) return; //メニュー無効 ui.menuBar->setEnabled(false); ui.toolBar->setEnabled(false); ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, true); ui.statusBar->showMessage(tr("making catalog"), -1); ui.progressBar->show(); ui.progressBar->setValue(0); for (int type = 0; type < shipRectList.size(); type++) { int tx = geometry.x() + (shipRectList.value(type).x() + qrand() % shipRectList.value(type).width()); int ty = geometry.y() + (shipRectList.value(type).y() + qrand() % shipRectList.value(type).height()); clickGame(QPoint(tx, ty)); for (int page = 0; page < pageRectList.size(); page++) { int px = geometry.x() + (pageRectList.value(page).x() + qrand() % pageRectList.value(page).width()); int py = geometry.y() + (pageRectList.value(page).y() + qrand() % pageRectList.value(page).height()); clickGame(QPoint(px, py)); QImage details = ui.webView->capture().copy(captureRect); painter.drawImage(captureRect.width() * type , captureRect.height() * page , details); ui.progressBar->setValue((pageRectList.size() * type + (page + 1)) * 100 / (pageRectList.size() * shipRectList.size()) ); } } ui.progressBar->hide(); ui.webView->page()->mainFrame()->setScrollPosition(currentPos); ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, false); ui.statusBar->showMessage("", -1); char format[] = "jpg"; QString path = makeFileName(QString(format)); qDebug() << "path:" << path; //保存する ui.statusBar->showMessage(tr("saving to %1...").arg(path), STATUS_BAR_MSG_TIME); if(resultImg.save(path, format)) { //つぶやくダイアログ openTweetDialog(path); }else{ ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME); } //メニュー復活 ui.menuBar->setEnabled(true); ui.toolBar->setEnabled(true); }
QDomElement variantToDomElement (const QVariant &v, QDomDocument &root) { QString result; QString type = QLatin1String("string"); QDomElement element; switch (v.type()) { case QVariant::StringList: case QVariant::List: case QVariant::Map: { return element; } case QVariant::Invalid: result = QLatin1String("@Invalid()"); break; case QVariant::ByteArray: { QByteArray a = v.toByteArray(); result = a.toBase64(); type = QLatin1String("data"); break; } case QVariant::String: { result = v.toString(); break; } case QVariant::LongLong: case QVariant::ULongLong: case QVariant::Int: case QVariant::UInt: { result = v.toString(); type = QLatin1String("integer"); break; } case QVariant::Bool: { element = root.createElement(v.toString()); return element; } case QVariant::Double: { result = v.toString(); type = QLatin1String("real"); break; } case QVariant::KeySequence: { result = v.toString(); if (result.startsWith(QLatin1Char('@'))) result.prepend(QLatin1Char('@')); break; } case QVariant::Rect: { QRect r = qvariant_cast<QRect>(v); result += QLatin1String("@Rect("); result += QString::number(r.x()); result += QLatin1Char(' '); result += QString::number(r.y()); result += QLatin1Char(' '); result += QString::number(r.width()); result += QLatin1Char(' '); result += QString::number(r.height()); result += QLatin1Char(')'); break; } case QVariant::Size: { QSize s = qvariant_cast<QSize>(v); result += QLatin1String("@Size("); result += QString::number(s.width()); result += QLatin1Char(' '); result += QString::number(s.height()); result += QLatin1Char(')'); break; } case QVariant::Point: { QPoint p = qvariant_cast<QPoint>(v); result += QLatin1String("@Point("); result += QString::number(p.x()); result += QLatin1Char(' '); result += QString::number(p.y()); result += QLatin1Char(')'); break; } default: { QByteArray a; { QDataStream s(&a, QIODevice::WriteOnly); s.setVersion(QDataStream::Qt_4_0); s << v; } result = QLatin1String("@Variant("); result += QString::fromLatin1(a.constData(), a.size()); result += QLatin1Char(')'); break; } } element = root.createElement(type); element.appendChild(root.createTextNode(result)); return element; }
void ImageOverlay::render(RenderArgs* args) { if (!_isLoaded && _renderImage) { _isLoaded = true; _texture = DependencyManager::get<TextureCache>()->getTexture(_imageURL); } // If we are not visible or loaded, return. If we are trying to render an // image but the texture hasn't loaded, return. if (!_visible || !_isLoaded || (_renderImage && !_texture->isLoaded())) { return; } if (_renderImage) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _texture->getID()); } const float MAX_COLOR = 255.0f; xColor color = getColor(); float alpha = getAlpha(); glm::vec4 quadColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); int left = _bounds.left(); int right = _bounds.right() + 1; int top = _bounds.top(); int bottom = _bounds.bottom() + 1; glm::vec2 topLeft(left, top); glm::vec2 bottomRight(right, bottom); // if for some reason our image is not over 0 width or height, don't attempt to render the image if (_renderImage) { float imageWidth = _texture->getWidth(); float imageHeight = _texture->getHeight(); if (imageWidth > 0 && imageHeight > 0) { QRect fromImage; if (_wantClipFromImage) { float scaleX = imageWidth / _texture->getOriginalWidth(); float scaleY = imageHeight / _texture->getOriginalHeight(); fromImage.setX(scaleX * _fromImage.x()); fromImage.setY(scaleY * _fromImage.y()); fromImage.setWidth(scaleX * _fromImage.width()); fromImage.setHeight(scaleY * _fromImage.height()); } else { fromImage.setX(0); fromImage.setY(0); fromImage.setWidth(imageWidth); fromImage.setHeight(imageHeight); } float x = fromImage.x() / imageWidth; float y = fromImage.y() / imageHeight; float w = fromImage.width() / imageWidth; // ?? is this what we want? not sure float h = fromImage.height() / imageHeight; glm::vec2 texCoordTopLeft(x, y); glm::vec2 texCoordBottomRight(x + w, y + h); DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor); } else { DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor); } glDisable(GL_TEXTURE_2D); } else { DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, quadColor); } }
QRect LDesktopPluginSpace::findOpenSpot(QRect grid, QString plugID, bool recursive){ //Reverse lookup spotc{ //This is just an overloaded simplification for checking currently existing plugins return findOpenSpot(grid.width(), grid.height(), grid.y(), grid.x(), recursive, plugID); }
QPixmap TileWidget::generateTilePixmap() { const QSize currentSize(size()); if (currentSize.isEmpty()) return QPixmap(); const QRect borderRect(0, 0, currentSize.width(), currentSize.height()); const int maxSideLength = qMax(currentSize.width(), currentSize.height()); const int borderWidth = 1; const QPointF midpoint((double)(currentSize.width() + borderWidth) / 2, (double)(currentSize.height() + borderWidth) / 2); const QColor color(tileColor()); QPixmap ret(currentSize); if (PixmapCacher::self()->contains(color)) ret = PixmapCacher::self()->get(color); else { //UVcout << "cache miss for color " << color.rgb() << endl; double radius = maxSideLength / 2 * 1.41 + maxSideLength / 10 + 2; // could be used for cool effect -- the color of the bonus square we're obscuring //const QColor outerColor(backgroundColor()); QRadialGradient gradient(QPointF(radius, radius), radius * 3, QPointF(radius / 3, radius / 3)); gradient.setColorAt(0, color.light(GraphicalBoardFrame::s_highlightFactor)); gradient.setColorAt(.95, color.dark(GraphicalBoardFrame::s_highlightFactor)); QPainter painter(&ret); painter.setBrush(gradient); painter.drawEllipse((int)(midpoint.x() - radius), (int)(midpoint.y() - radius), (int)(radius * 2), (int)(radius * 2)); QPalette customPalette; customPalette.setColor(QPalette::Light, color.light(GraphicalBoardFrame::s_highlightFactor)); customPalette.setColor(QPalette::Dark, color); customPalette.setColor(QPalette::Mid, color); qDrawShadePanel(&painter, borderRect.x(), borderRect.y(), borderRect.width(), borderRect.height(), customPalette, false, borderWidth); PixmapCacher::self()->put(color, ret); } const QString nanism = miniText(); const bool hasNanism = !nanism.isEmpty(); const QString text = letterText(); if (!text.isEmpty()) { QPainter painter(&ret); painter.setFont(letterFont()); QPen pen(letterTextColor()); painter.setPen(pen); painter.setBrush(Qt::NoBrush); const QRectF textSize(painter.boundingRect(borderRect, text)); const QPointF startPoint(midpoint - textSize.bottomRight() / 2); const QPointF roundedStartPoint(floor(startPoint.x()), floor(startPoint.y())); QRectF textRect(textSize); textRect.moveTo(roundedStartPoint); painter.drawText(textRect, Qt::TextDontClip, text); if (m_information.isBlank) { painter.setBrush(Qt::NoBrush); pen.setWidth(1); painter.setPen(pen); const int border = currentSize.width() / 5; painter.drawRect(QRect(border, border, currentSize.width() - 2 * border, currentSize.height() - 2 * border)); } } if (hasNanism) { QPainter painter(&ret); painter.setFont(miniFont()); QPen pen(miniTextColor()); painter.setPen(pen); painter.setBrush(Qt::NoBrush); const QRectF textSize(painter.boundingRect(borderRect, nanism)); const QPointF startPoint((midpoint * (nanism.length() > 1? 1.65 : 1.68)) - textSize.bottomRight() / 2); const QPointF roundedStartPoint(floor(startPoint.x()), floor(startPoint.y())); QRectF textRect(textSize); textRect.moveTo(roundedStartPoint); painter.drawText(textRect, Qt::TextDontClip, nanism); } return ret; }
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e) { bool ok = true; clearAttributes(e); switch (v.type()) { case QVariant::String: e.setTagName("string"); e.setAttribute("value", v.toString().utf8()); break; case QVariant::CString: e.setTagName("string"); e.setAttribute("value", v.toCString()); break; case QVariant::Int: e.setTagName("int"); e.setAttribute("value", v.toInt()); break; case QVariant::UInt: e.setTagName("uint"); e.setAttribute("value", v.toUInt()); break; case QVariant::Double: e.setTagName("double"); e.setAttribute("value", v.toDouble()); break; case QVariant::Bool: e.setTagName("bool"); e.setAttribute("value", boolString(v.toBool())); break; case QVariant::Color: { e.setTagName("color"); QColor color = v.toColor(); e.setAttribute("red", color.red()); e.setAttribute("green", color.green()); e.setAttribute("blue", color.blue()); } break; case QVariant::Point: { e.setTagName("point"); QPoint point = v.toPoint(); e.setAttribute("x", point.x()); e.setAttribute("y", point.y()); } break; case QVariant::Rect: { e.setTagName("rect"); QRect rect = v.toRect(); e.setAttribute("x", rect.x()); e.setAttribute("y", rect.y()); e.setAttribute("width", rect.width()); e.setAttribute("height", rect.height()); } break; case QVariant::Size: { e.setTagName("size"); QSize qsize = v.toSize(); e.setAttribute("width", qsize.width()); e.setAttribute("height", qsize.height()); } break; case QVariant::Font: { e.setTagName("font"); QFont f(v.toFont()); e.setAttribute("family", f.family()); e.setAttribute("pointsize", f.pointSize()); e.setAttribute("bold", boolString(f.bold())); e.setAttribute("italic", boolString(f.italic())); e.setAttribute("underline", boolString(f.underline())); e.setAttribute("strikeout", boolString(f.strikeOut())); } break; case QVariant::SizePolicy: { e.setTagName("sizepolicy"); QSizePolicy sp(v.toSizePolicy()); e.setAttribute("hsizetype", sp.horData()); e.setAttribute("vsizetype", sp.verData()); #if (QT_VERSION >= 300) e.setAttribute("horstretch", sp.horStretch()); e.setAttribute("verstretch", sp.verStretch()); #endif } break; case QVariant::Cursor: e.setTagName("cursor"); e.setAttribute("shape", v.toCursor().shape()); break; case QVariant::StringList: { e.setTagName("stringlist"); uint j; QDomNode n; QDomNodeList stringNodeList = e.elementsByTagName("string"); QDomElement stringElem; QStringList stringList = v.toStringList(); QStringList::Iterator it = stringList.begin(); for (j = 0; ((j < stringNodeList.length()) && (it != stringList.end())); j++) { // get the current string element stringElem = stringNodeList.item(j).toElement(); // set it to the current string variantToElement(QVariant(*it), stringElem); // iterate to the next string ++it; } // more nodes in previous stringlist then current, remove excess nodes if (stringNodeList.count() > stringList.count()) { while (j < stringNodeList.count()) e.removeChild(stringNodeList.item(j).toElement()); } else if (j <stringList.count()) { while (it != stringList.end()) { // create a new element stringElem = m_doc.createElement("string"); // set it to the currentstring variantToElement(QVariant(*it), stringElem); // append it to the current element e.appendChild(stringElem); // iterate to the next string ++it; } } } break; #if QT_VERSION >= 300 case QVariant::KeySequence: e.setTagName("key"); e.setAttribute("sequence", (QString)v.toKeySequence()); break; #endif #if 0 case QVariant::List: case QVaraint::Map: #endif default: qWarning("Don't know how to persist variant of type: %s (%d)!", v.typeName(), v.type()); ok = false; break; } return ok; }
/** * \brief Get screen size from Qt, respecting for user's multiple screen prefs * * If the windowing system environment has multiple screens * (%e.g. Xinerama or Mac OS X), QApplication::desktop()->%width() will span * all of them, so we usually need to get the geometry of a specific screen. */ void MythUIHelperPrivate::GetScreenBounds() { QDesktopWidget *desktop = QApplication::desktop(); bool hasXinerama = MythDisplay::GetNumberXineramaScreens() > 1; int numScreens = desktop->numScreens(); int screen; if (hasXinerama) { LOG(VB_GUI, LOG_INFO, LOC + QString("Total desktop dim: %1x%2, over %3 screen[s].") .arg(desktop->width()).arg(desktop->height()).arg(numScreens)); } if (numScreens > 1) { for (screen = 0; screen < numScreens; ++screen) { QRect dim = desktop->screenGeometry(screen); LOG(VB_GUI, LOG_INFO, LOC + QString("Screen %1 dim: %2x%3.") .arg(screen).arg(dim.width()).arg(dim.height())); } } screen = desktop->primaryScreen(); LOG(VB_GUI, LOG_INFO, LOC + QString("Primary screen: %1.").arg(screen)); if (hasXinerama) screen = GetMythDB()->GetNumSetting("XineramaScreen", screen); if (screen == -1) // Special case - span all screens { m_xbase = 0; m_ybase = 0; m_width = desktop->width(); m_height = desktop->height(); LOG(VB_GUI, LOG_INFO, LOC + QString("Using all %1 screens. ").arg(numScreens) + QString("Dimensions: %1x%2").arg(m_width).arg(m_height)); return; } if (hasXinerama) // User specified a single screen { if (screen < 0 || screen >= numScreens) { LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Xinerama screen %1 was specified," " but only %2 available, so using screen 0.") .arg(screen).arg(numScreens)); screen = 0; } } { QRect bounds; bool inWindow = GetMythDB()->GetNumSetting("RunFrontendInWindow", 0); if (inWindow) LOG(VB_GUI, LOG_INFO, LOC + "Running in a window"); if (inWindow) // This doesn't include the area occupied by the // Windows taskbar, or the Mac OS X menu bar and Dock bounds = desktop->availableGeometry(screen); else bounds = desktop->screenGeometry(screen); m_xbase = bounds.x(); m_ybase = bounds.y(); m_width = bounds.width(); m_height = bounds.height(); LOG(VB_GUI, LOG_INFO, LOC + QString("Using screen %1, %2x%3 at %4,%5") .arg(screen).arg(m_width).arg(m_height) .arg(m_xbase).arg(m_ybase)); } }
Screen2::Screen2(QWidget *parent) : QWidget(parent), ui(new Ui::Screen2), airTime() { ui->setupUi(this); QScreen* screen; if(QApplication::screens().size() > 1){ screen = QApplication::screens().at(1); } else { screen = QApplication::screens().at(0); } QRect screenres = screen->geometry(); this->move(QPoint(screenres.x(), screenres.y())); this->resize(screenres.width(), screenres.height()); QPalette palette = this->palette(); palette.setColor(this->backgroundRole(), Qt::black); this->setPalette(palette); // QPalette pText = ui->label_height->palette(); // palette.setColor(ui->label_height->foregroundRole(), Qt::white); // ui->label_height->setPalette(pText); // ui->label_state->setPalette(pText); // ui->label_time->setPalette(pText); mCompassGauge = new QcGaugeWidget; QcLabelItem *w = mCompassGauge->addLabel(60); w->setText("W"); w->setAngle(0); w->setColor(Qt::black); QcLabelItem *n = mCompassGauge->addLabel(60); n->setText("N"); n->setAngle(90); n->setColor(Qt::black); QcLabelItem *e = mCompassGauge->addLabel(60); e->setText("E"); e->setAngle(180); e->setColor(Qt::black); QcLabelItem *s = mCompassGauge->addLabel(60); s->setText("S"); s->setAngle(270); s->setColor(Qt::black); QcDegreesItem *deg = mCompassGauge->addDegrees(50); deg->setStep(5); deg->setMaxDegree(360); deg->setMinDegree(0); deg->setColor(Qt::black); lab = mCompassGauge->addLabel(75); mShipNeedle = mCompassGauge->addNeedle(55); mShipNeedle->setNeedle(QcNeedleItem::AttitudeMeterNeedle); mShipNeedle->setValueRange(-360,360); mShipNeedle->setMaxDegree(360); mShipNeedle->setMinDegree(-360); mShipNeedle->setColor(Qt::green); mHeadingNeedle = mCompassGauge->addNeedle(45); mHeadingNeedle->setNeedle(QcNeedleItem::DiamonNeedle); mHeadingNeedle->setValueRange(0,360); mHeadingNeedle->setMaxDegree(360); mHeadingNeedle->setMinDegree(0); mHeadingNeedle->setColor(Qt::red); ui->compassLayout->addWidget(mCompassGauge); time = new QTime; timer = new QTimer; connect(timer, SIGNAL(timeout()), this, SLOT(updateTime())); timer->start(1000); hr = 0; min = 0; sec = 0; oldmsec = 0; timerOn = false; airTime.setHMS(hr, min, sec); }
QList<int> SM::findHighlight( QRect rect ) { QList<int> frameIndex; _INIT = false; highLightedList.clear(); int selected = -1; int begin = TDHelper::Min( rect.topLeft().x(), rect.topRight().x() ); int end = begin + abs( rect.width() ); for(int i = 0; i < 3; i++) { int currentX = i*SPACE + OFFSET; if( currentX >= begin && currentX <= end ) { selected = i; } } if( selected == -1 ) { return frameIndex; } // begin find if( this->_data[selected]->getType() == 2 ) { int endFrame = this->mapFrame( rect.y() ); int beginFrame = this->mapFrame( rect.y() + rect.height() ); for( int i = beginFrame; i <= endFrame; i++ ) { highLightedList.append( i ); frameIndex.append( i ); } } else if( this->_data[selected]->getType() == 1 || this->_data[selected]->getType() == 3 ) { // find max int maxHeight, minHeight; maxHeight = TDHelper::Max( rect.y(), rect.y() + rect.height() ); minHeight = TDHelper::Min( rect.y(), rect.y() + rect.height() ); //************************************************ float curDataMAM = this->_data[selected]->getMIN() - (( this->HEIGHT/2.0f - minHeight ) * ( this->_data[selected]->getMIN() - this->_data[selected]->getMAX() ) / this->HEIGHT ); float curDataMIN = this->_data[selected]->getMIN() - (( this->HEIGHT/2.0f - maxHeight ) * ( this->_data[selected]->getMIN() - this->_data[selected]->getMAX() ) / this->HEIGHT ); //************************************************ //maxHeight = //max = this->HEIGHT/2 - rect.y(); //max = _data[1]->getMAX() * max / this->HEIGHT; //min = this->HEIGHT/2 - rect.y() - rect.height(); //min = _data[selected]->getMIN * min / this->HEIGHT; // for( int i = 0; i < 50; i++) { float percent = _data[selected]->percentage_At(i); float currentValue = percent * ( _data[selected]->getMAX() - _data[selected]->getMIN() ) + _data[selected]->getMIN() ; if( currentValue >= curDataMIN && currentValue <= curDataMAM ) { highLightedList.append( i ); frameIndex.append( int( _data[1]->percentage_At(i) * ( _data[1]->getMAX() - _data[1]->getMIN() ) + _data[1]->getMIN() )); } } } return frameIndex; }
void StyleHelper::drawArrow(QStyle::PrimitiveElement element, QPainter *painter, const QStyleOption *option) { // From windowsstyle but modified to enable AA if (option->rect.width() <= 1 || option->rect.height() <= 1) return; QRect r = option->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; QString pixmapName; pixmapName.sprintf("arrow-%s-%d-%d-%d-%lld", "$qt_ia", uint(option->state), element, size, option->palette.cacheKey()); if (!QPixmapCache::find(pixmapName, pixmap)) { int border = size/5; int sqsize = 2*(size/2); QImage image(sqsize, sqsize, QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter imagePainter(&image); imagePainter.setRenderHint(QPainter::Antialiasing, true); imagePainter.translate(0.5, 0.5); QPolygon a; switch (element) { case QStyle::PE_IndicatorArrowUp: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); break; case QStyle::PE_IndicatorArrowDown: a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); break; case QStyle::PE_IndicatorArrowRight: a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; case QStyle::PE_IndicatorArrowLeft: a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); break; default: break; } int bsx = 0; int bsy = 0; if (option->state & QStyle::State_Sunken) { bsx = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal); bsy = qApp->style()->pixelMetric(QStyle::PM_ButtonShiftVertical); } QRect bounds = a.boundingRect(); int sx = sqsize / 2 - bounds.center().x() - 1; int sy = sqsize / 2 - bounds.center().y() - 1; imagePainter.translate(sx + bsx, sy + bsy); if (!(option->state & QStyle::State_Enabled)) { QColor foreGround(150, 150, 150, 150); imagePainter.setBrush(option->palette.mid().color()); imagePainter.setPen(option->palette.mid().color()); } else { QColor shadow(0, 0, 0, 100); imagePainter.translate(0, 1); imagePainter.setPen(shadow); imagePainter.setBrush(shadow); QColor foreGround(255, 255, 255, 210); imagePainter.drawPolygon(a); imagePainter.translate(0, -1); imagePainter.setPen(foreGround); imagePainter.setBrush(foreGround); } imagePainter.drawPolygon(a); imagePainter.end(); pixmap = QPixmap::fromImage(image); QPixmapCache::insert(pixmapName, pixmap); } int xOffset = r.x() + (r.width() - size)/2; int yOffset = r.y() + (r.height() - size)/2; painter->drawPixmap(xOffset, yOffset, pixmap); }
QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const { Q_D(const QMacPrintEngine); QVariant ret; if (!d->session && d->valueCache.contains(key)) return *d->valueCache.find(key); switch (key) { case PPK_CollateCopies: ret = false; break; case PPK_ColorMode: ret = QPrinter::Color; break; case PPK_Creator: break; case PPK_DocumentName: break; case PPK_FullPage: ret = d->fullPage; break; case PPK_NumberOfCopies: ret = 1; break; case PPK_Orientation: PMOrientation orientation; PMGetOrientation(d->format, &orientation); ret = orientation == kPMPortrait ? QPrinter::Portrait : QPrinter::Landscape; break; case PPK_OutputFileName: ret = d->outputFilename; break; case PPK_PageOrder: break; case PPK_PaperSource: break; case PPK_PageRect: { // PageRect is returned in device pixels QRect r; PMRect macrect, macpaper; qreal hRatio = d->resolution.hRes / 72; qreal vRatio = d->resolution.vRes / 72; if (d->hasCustomPaperSize) { r = QRect(0, 0, qRound(d->customSize.width() * hRatio), qRound(d->customSize.height() * vRatio)); if (d->hasCustomPageMargins) { r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio), -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio)); } else { QList<QVariant> margins = property(QPrintEngine::PPK_PageMargins).toList(); r.adjust(qRound(margins.at(0).toDouble() * hRatio), qRound(margins.at(1).toDouble() * vRatio), -qRound(margins.at(2).toDouble() * hRatio), -qRound(margins.at(3).toDouble()) * vRatio); } } else if (PMGetAdjustedPageRect(d->format, ¯ect) == noErr && PMGetAdjustedPaperRect(d->format, &macpaper) == noErr) { if (d->fullPage || d->hasCustomPageMargins) { r.setCoords(int(macpaper.left * hRatio), int(macpaper.top * vRatio), int(macpaper.right * hRatio), int(macpaper.bottom * vRatio)); r.translate(-r.x(), -r.y()); if (d->hasCustomPageMargins) { r.adjust(qRound(d->leftMargin * hRatio), qRound(d->topMargin * vRatio), -qRound(d->rightMargin * hRatio), -qRound(d->bottomMargin * vRatio)); } } else { r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio), int(macrect.right * hRatio), int(macrect.bottom * vRatio)); r.translate(int(-macpaper.left * hRatio), int(-macpaper.top * vRatio)); } } ret = r; break; } case PPK_PaperSize: ret = d->paperSize(); break; case PPK_PaperRect: { QRect r; PMRect macrect; if (d->hasCustomPaperSize) { r = QRect(0, 0, qRound(d->customSize.width()), qRound(d->customSize.height())); } else if (PMGetAdjustedPaperRect(d->format, ¯ect) == noErr) { qreal hRatio = d->resolution.hRes / 72; qreal vRatio = d->resolution.vRes / 72; r.setCoords(int(macrect.left * hRatio), int(macrect.top * vRatio), int(macrect.right * hRatio), int(macrect.bottom * vRatio)); r.translate(-r.x(), -r.y()); } ret = r; break; } case PPK_PrinterName: { CFIndex currIndex; PMPrinter unused; QCFType<CFArrayRef> printerList; OSStatus status = PMSessionCreatePrinterList(d->session, &printerList, &currIndex, &unused); if (status != noErr) qWarning("QMacPrintEngine::printerName: Problem getting list of printers: %ld", long(status)); if (currIndex != -1 && printerList && currIndex < CFArrayGetCount(printerList)) { const CFStringRef name = static_cast<CFStringRef>(CFArrayGetValueAtIndex(printerList, currIndex)); if (name) ret = QCFString::toQString(name); } break; } case PPK_Resolution: { ret = d->resolution.hRes; break; } case PPK_SupportedResolutions: ret = d->supportedResolutions(); break; case PPK_CustomPaperSize: ret = d->customSize; break; case PPK_PageMargins: { QList<QVariant> margins; if (d->hasCustomPageMargins) { margins << d->leftMargin << d->topMargin << d->rightMargin << d->bottomMargin; } else { PMPaperMargins paperMargins; PMPaper paper; PMGetPageFormatPaper(d->format, &paper); PMPaperGetMargins(paper, &paperMargins); margins << paperMargins.left << paperMargins.top << paperMargins.right << paperMargins.bottom; } ret = margins; break; } default: break; } return ret; }
void OdClassInstCanvas::draw(QPainter & p) { if (visible()) { QRect r = rect(); QFontMetrics fm(the_canvas()->get_font(UmlNormalFont)); QColor bckgrnd = p.backgroundColor(); double zoom = the_canvas()->zoom(); p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode); QColor co = color(used_color); FILE * fp = svg(); if (fp != 0) fputs("<g>\n", fp); if (used_color != UmlTransparent) { const int shadow = the_canvas()->shadow(); if (shadow != 0) { r.setRight(r.right() - shadow); r.setBottom(r.bottom() - shadow); p.fillRect (r.right(), r.top() + shadow, shadow, r.height() - 1, ::Qt::darkGray); p.fillRect (r.left() + shadow, r.bottom(), r.width() - 1, shadow, ::Qt::darkGray); if (fp != 0) { fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", ::Qt::darkGray.rgb()&0xffffff, r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1); fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", ::Qt::darkGray.rgb()&0xffffff, r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1); } } } p.setBackgroundColor(co); if (used_color != UmlTransparent) p.fillRect(r, co); if (fp != 0) fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\"" " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n", svg_color(used_color), r.x(), r.y(), r.width() - 1, r.height() - 1); p.drawRect(r); BrowserClass * cl = ((ClassInstanceData *) browser_node->get_data())->get_class(); if (((ClassData *) cl->get_data())->get_is_active()) { const int eight = (int) (8 * zoom); r.setLeft(r.left() + eight); r.setRight(r.right() - eight); p.drawLine(r.topLeft(), r.bottomLeft()); p.drawLine(r.topRight(), r.bottomRight()); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n" "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.left(), r.top(), r.left(), r.bottom(), r.right(), r.top(), r.right(), r.bottom()); } const int two = (int) (2 * zoom); int he = fm.height() + two; p.setFont(the_canvas()->get_font(UmlNormalUnderlinedFont)); r.setTop(r.top() + two); if (horiz) { p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name()); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name(), p.font(), fp); } else { p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, get_name() + ":"); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, get_name() + ":", p.font(), fp); r.setTop(r.top() + fm.height()); p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, cl->contextual_name(used_show_context_mode)); if (fp != 0) draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, cl->contextual_name(used_show_context_mode), p.font(), fp); } p.setFont(the_canvas()->get_font(UmlNormalFont)); const QValueList<SlotAttr> & attributes = ((ClassInstanceData *) browser_node->get_data())->get_attributes(); if (!attributes.isEmpty()) { r.setTop(r.top() + he + two); p.drawLine(r.topLeft(), r.topRight()); if (fp != 0) fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\"" " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", r.left(), r.top(), r.right(), r.top()); r.setTop(r.top() + two); r.setLeft(r.left() + (int) (4 * zoom)); QValueList<SlotAttr>::ConstIterator it = attributes.begin(); QString egal = " = "; do { QString s = (*it).att->get_name() + egal + (*it).value; p.drawText(r, ::Qt::AlignTop, s); if (fp != 0) draw_text(r, ::Qt::AlignTop, s, p.font(), fp); r.setTop(r.top() + he); ++it; } while (it != attributes.end()); } if (fp != 0) fputs("</g>\n", fp); if (selected()) show_mark(p, rect()); } }
void UBRubberBand::mouseMoveEvent(QMouseEvent *event) { determineResizingMode(event->pos()); if (mMouseIsPressed) { UBBoardView *view = UBApplication::boardController->controlView(); QRect currentGeometry = geometry(); QPoint pressPoint(event->pos()); QPoint pressPointGlobal(view->mapToGlobal(pressPoint)); QPoint prevPressPointGlobal(view->mapToGlobal(mLastPressedPoint)); QPoint movePointGlogal = (view->mapToGlobal(mLastMousePos)); QPoint topLeftResizeVector(pressPointGlobal - prevPressPointGlobal); QPoint rightBottomResizeVector(pressPointGlobal - movePointGlogal); bool bGeometryChange = true; switch(mResizingMode) { case None: { QPointF itemsMoveVector(view->mapToScene(pressPointGlobal) - view->mapToScene(prevPressPointGlobal)); move(pos()+pressPointGlobal - prevPressPointGlobal); view->moveRubberedItems(itemsMoveVector); bGeometryChange = false; break; } case Top: { currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y()); }break; case Bottom: { currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y()); }break; case Left: { currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x()); }break; case Right: { currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x()); }break; case TopLeft: { currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x()); currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y()); }break; case TopRight: { currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y()); currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x()); } break; case BottomLeft: { currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x()); currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y()); }break; case BottomRight: { currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x()); currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y()); }break; } if(bGeometryChange) { setGeometry(currentGeometry); } mLastMousePos = event->pos(); } QRubberBand::mouseMoveEvent(event); }
void QwtPlot::printScale(QPainter *painter, int axis, int startDist, int endDist, int baseDist, const QRect &rect) const { if (!d_axisEnabled[axis]) return; QwtScaleDraw::Orientation o; int x, y, w; switch(axis) { case yLeft: { x = rect.right() - baseDist; y = rect.y() + startDist; w = rect.height() - startDist - endDist; o = QwtScaleDraw::Left; break; } case yRight: { x = rect.left() + baseDist; y = rect.y() + startDist; w = rect.height() - startDist - endDist; o = QwtScaleDraw::Right; break; } case xTop: { x = rect.left() + startDist; y = rect.bottom() - baseDist; w = rect.width() - startDist - endDist; o = QwtScaleDraw::Top; break; } case xBottom: { x = rect.left() + startDist; y = rect.top() + baseDist; w = rect.width() - startDist - endDist; o = QwtScaleDraw::Bottom; break; } default: return; } const QwtScale *scale = d_scale[axis]; scale->drawTitle(painter, o, rect); painter->save(); QPen pen(painter->pen()); pen.setColor( scale->palette().color(QPalette::Active, QColorGroup::Foreground)); painter->setPen(pen); painter->setFont(scale->font()); QwtScaleDraw *sd = (QwtScaleDraw *)scale->scaleDraw(); int xSd = sd->x(); int ySd = sd->y(); int lengthSd = sd->length(); sd->setGeometry(x, y, w, o); sd->draw(painter); sd->setGeometry(xSd, ySd, lengthSd, o); // reset previous values painter->restore(); }
/*! \reimp */ QRect Q3AccessibleHeader::rect(int child) const { QPoint zero = header()->mapToGlobal(QPoint(0, 0)); QRect sect = header()->sectionRect(child - 1); return QRect(sect.x() + zero.x(), sect.y() + zero.y(), sect.width(), sect.height()); }
static bool read_jpeg_image(QImage *outImage, QSize scaledSize, QRect scaledClipRect, QRect clipRect, volatile int inQuality, j_decompress_ptr info, struct my_error_mgr* err ) { if (!setjmp(err->setjmp_buffer)) { // -1 means default quality. int quality = inQuality; if (quality < 0) quality = 75; // If possible, merge the scaledClipRect into either scaledSize // or clipRect to avoid doing a separate scaled clipping pass. // Best results are achieved by clipping before scaling, not after. if (!scaledClipRect.isEmpty()) { if (scaledSize.isEmpty() && clipRect.isEmpty()) { // No clipping or scaling before final clip. clipRect = scaledClipRect; scaledClipRect = QRect(); } else if (scaledSize.isEmpty()) { // Clipping, but no scaling: combine the clip regions. scaledClipRect.translate(clipRect.topLeft()); clipRect = scaledClipRect.intersected(clipRect); scaledClipRect = QRect(); } else if (clipRect.isEmpty()) { // No clipping, but scaling: if we can map back to an // integer pixel boundary, then clip before scaling. if ((info->image_width % scaledSize.width()) == 0 && (info->image_height % scaledSize.height()) == 0) { int x = scaledClipRect.x() * info->image_width / scaledSize.width(); int y = scaledClipRect.y() * info->image_height / scaledSize.height(); int width = (scaledClipRect.right() + 1) * info->image_width / scaledSize.width() - x; int height = (scaledClipRect.bottom() + 1) * info->image_height / scaledSize.height() - y; clipRect = QRect(x, y, width, height); scaledSize = scaledClipRect.size(); scaledClipRect = QRect(); } } else { // Clipping and scaling: too difficult to figure out, // and not a likely use case, so do it the long way. } } // Determine the scale factor to pass to libjpeg for quick downscaling. if (!scaledSize.isEmpty() && info->image_width && info->image_height) { if (clipRect.isEmpty()) { double f = qMin(double(info->image_width) / scaledSize.width(), double(info->image_height) / scaledSize.height()); // libjpeg supports M/8 scaling with M=[1,16]. All downscaling factors // are a speed improvement, but upscaling during decode is slower. info->scale_num = qBound(1, qCeil(8/f), 8); info->scale_denom = 8; } else { info->scale_denom = qMin(clipRect.width() / scaledSize.width(), clipRect.height() / scaledSize.height()); // Only scale by powers of two when clipping so we can // keep the exact pixel boundaries if (info->scale_denom < 2) info->scale_denom = 1; else if (info->scale_denom < 4) info->scale_denom = 2; else if (info->scale_denom < 8) info->scale_denom = 4; else info->scale_denom = 8; info->scale_num = 1; // Correct the scale factor so that we clip accurately. // It is recommended that the clip rectangle be aligned // on an 8-pixel boundary for best performance. while (info->scale_denom > 1 && ((clipRect.x() % info->scale_denom) != 0 || (clipRect.y() % info->scale_denom) != 0 || (clipRect.width() % info->scale_denom) != 0 || (clipRect.height() % info->scale_denom) != 0)) { info->scale_denom /= 2; } } } // If high quality not required, use fast decompression if( quality < HIGH_QUALITY_THRESHOLD ) { info->dct_method = JDCT_IFAST; info->do_fancy_upsampling = false; } (void) jpeg_calc_output_dimensions(info); // Determine the clip region to extract. QRect imageRect(0, 0, info->output_width, info->output_height); QRect clip; if (clipRect.isEmpty()) { clip = imageRect; } else if (info->scale_denom == info->scale_num) { clip = clipRect.intersected(imageRect); } else { // The scale factor was corrected above to ensure that // we don't miss pixels when we scale the clip rectangle. clip = QRect(clipRect.x() / int(info->scale_denom), clipRect.y() / int(info->scale_denom), clipRect.width() / int(info->scale_denom), clipRect.height() / int(info->scale_denom)); clip = clip.intersected(imageRect); } // Allocate memory for the clipped QImage. if (!ensureValidImage(outImage, info, clip.size())) longjmp(err->setjmp_buffer, 1); // Avoid memcpy() overhead if grayscale with no clipping. bool quickGray = (info->output_components == 1 && clip == imageRect); if (!quickGray) { // Ask the jpeg library to allocate a temporary row. // The library will automatically delete it for us later. // The libjpeg docs say we should do this before calling // jpeg_start_decompress(). We can't use "new" here // because we are inside the setjmp() block and an error // in the jpeg input stream would cause a memory leak. JSAMPARRAY rows = (info->mem->alloc_sarray) ((j_common_ptr)info, JPOOL_IMAGE, info->output_width * info->output_components, 1); (void) jpeg_start_decompress(info); while (info->output_scanline < info->output_height) { int y = int(info->output_scanline) - clip.y(); if (y >= clip.height()) break; // We've read the entire clip region, so abort. (void) jpeg_read_scanlines(info, rows, 1); if (y < 0) continue; // Haven't reached the starting line yet. if (info->output_components == 3) { uchar *in = rows[0] + clip.x() * 3; QRgb *out = (QRgb*)outImage->scanLine(y); rgb888ToRgb32ConverterPtr(out, in, clip.width()); } else if (info->out_color_space == JCS_CMYK) { // Convert CMYK->RGB. uchar *in = rows[0] + clip.x() * 4; QRgb *out = (QRgb*)outImage->scanLine(y); for (int i = 0; i < clip.width(); ++i) { int k = in[3]; *out++ = qRgb(k * in[0] / 255, k * in[1] / 255, k * in[2] / 255); in += 4; } } else if (info->output_components == 1) { // Grayscale. memcpy(outImage->scanLine(y), rows[0] + clip.x(), clip.width()); } } } else { // Load unclipped grayscale data directly into the QImage. (void) jpeg_start_decompress(info); while (info->output_scanline < info->output_height) { uchar *row = outImage->scanLine(info->output_scanline); (void) jpeg_read_scanlines(info, &row, 1); } } if (info->output_scanline == info->output_height) (void) jpeg_finish_decompress(info); if (info->density_unit == 1) { outImage->setDotsPerMeterX(int(100. * info->X_density / 2.54)); outImage->setDotsPerMeterY(int(100. * info->Y_density / 2.54)); } else if (info->density_unit == 2) { outImage->setDotsPerMeterX(int(100. * info->X_density)); outImage->setDotsPerMeterY(int(100. * info->Y_density)); } if (scaledSize.isValid() && scaledSize != clip.size()) { *outImage = outImage->scaled(scaledSize, Qt::IgnoreAspectRatio, quality >= HIGH_QUALITY_THRESHOLD ? Qt::SmoothTransformation : Qt::FastTransformation); } if (!scaledClipRect.isEmpty()) *outImage = outImage->copy(scaledClipRect); return !outImage->isNull(); } else return false; }
void ScrollZoomer::layoutScrollBars(const QRect &rect) { int hPos = xAxis(); if ( hScrollBarPosition() == OppositeToScale ) hPos = oppositeAxis(hPos); int vPos = yAxis(); if ( vScrollBarPosition() == OppositeToScale ) vPos = oppositeAxis(vPos); ScrollBar *hScrollBar = horizontalScrollBar(); ScrollBar *vScrollBar = verticalScrollBar(); const int hdim = hScrollBar ? hScrollBar->extent() : 0; const int vdim = vScrollBar ? vScrollBar->extent() : 0; if ( hScrollBar && hScrollBar->isVisible() ) { int x = rect.x(); int y = (hPos == QwtPlot::xTop) ? rect.top() : rect.bottom() - hdim + 1; int w = rect.width(); if ( vScrollBar && vScrollBar->isVisible() ) { if ( vPos == QwtPlot::yLeft ) x += vdim; w -= vdim; } hScrollBar->setGeometry(x, y, w, hdim); } if ( vScrollBar && vScrollBar->isVisible() ) { int pos = yAxis(); if ( vScrollBarPosition() == OppositeToScale ) pos = oppositeAxis(pos); int x = (vPos == QwtPlot::yLeft) ? rect.left() : rect.right() - vdim + 1; int y = rect.y(); int h = rect.height(); if ( hScrollBar && hScrollBar->isVisible() ) { if ( hPos == QwtPlot::xTop ) y += hdim; h -= hdim; } vScrollBar->setGeometry(x, y, vdim, h); } if ( hScrollBar && hScrollBar->isVisible() && vScrollBar && vScrollBar->isVisible() ) { if ( d_cornerWidget ) { QRect cornerRect( vScrollBar->pos().x(), hScrollBar->pos().y(), vdim, hdim); d_cornerWidget->setGeometry(cornerRect); } } }
void IsometricRenderer::drawTileLayer(QPainter *painter, const TileLayer *layer, const QRectF &exposed) const { const int tileWidth = map()->tileWidth(); const int tileHeight = map()->tileHeight(); if (tileWidth <= 0 || tileHeight <= 1) return; QRect rect = exposed.toAlignedRect(); if (rect.isNull()) rect = boundingRect(layer->bounds()); QMargins drawMargins = layer->drawMargins(); drawMargins.setTop(drawMargins.top() - tileHeight); drawMargins.setRight(drawMargins.right() - tileWidth); rect.adjust(-drawMargins.right(), -drawMargins.bottom(), drawMargins.left(), drawMargins.top()); // Determine the tile and pixel coordinates to start at QPointF tilePos = pixelToTileCoords(rect.x(), rect.y()); QPoint rowItr = QPoint((int) std::floor(tilePos.x()), (int) std::floor(tilePos.y())); QPointF startPos = tileToPixelCoords(rowItr); startPos.rx() -= tileWidth / 2; startPos.ry() += tileHeight; // Compensate for the layer position rowItr -= QPoint(layer->x(), layer->y()); /* Determine in which half of the tile the top-left corner of the area we * need to draw is. If we're in the upper half, we need to start one row * up due to those tiles being visible as well. How we go up one row * depends on whether we're in the left or right half of the tile. */ const bool inUpperHalf = startPos.y() - rect.y() > tileHeight / 2; const bool inLeftHalf = rect.x() - startPos.x() < tileWidth / 2; if (inUpperHalf) { if (inLeftHalf) { --rowItr.rx(); startPos.rx() -= tileWidth / 2; } else { --rowItr.ry(); startPos.rx() += tileWidth / 2; } startPos.ry() -= tileHeight / 2; } // Determine whether the current row is shifted half a tile to the right bool shifted = inUpperHalf ^ inLeftHalf; QTransform baseTransform = painter->transform(); for (int y = startPos.y(); y - tileHeight < rect.bottom(); y += tileHeight / 2) { QPoint columnItr = rowItr; for (int x = startPos.x(); x < rect.right(); x += tileWidth) { if (layer->contains(columnItr)) { const Cell &cell = layer->cellAt(columnItr); if (!cell.isEmpty()) { const QPixmap &img = cell.tile->image(); const QPoint offset = cell.tile->tileset()->tileOffset(); qreal m11 = 1; // Horizontal scaling factor qreal m12 = 0; // Vertical shearing factor qreal m21 = 0; // Horizontal shearing factor qreal m22 = 1; // Vertical scaling factor qreal dx = offset.x() + x; qreal dy = offset.y() + y - img.height(); if (cell.flippedAntiDiagonally) { // Use shearing to swap the X/Y axis m11 = 0; m12 = 1; m21 = 1; m22 = 0; // Compensate for the swap of image dimensions dy += img.height() - img.width(); } if (cell.flippedHorizontally) { m11 = -m11; m21 = -m21; dx += cell.flippedAntiDiagonally ? img.height() : img.width(); } if (cell.flippedVertically) { m12 = -m12; m22 = -m22; dy += cell.flippedAntiDiagonally ? img.width() : img.height(); } const QTransform transform(m11, m12, m21, m22, dx, dy); painter->setTransform(transform * baseTransform); painter->drawPixmap(0, 0, img); } } // Advance to the next column ++columnItr.rx(); --columnItr.ry(); } // Advance to the next row if (!shifted) { ++rowItr.rx(); startPos.rx() += tileWidth / 2; shifted = true; } else { ++rowItr.ry(); startPos.rx() -= tileWidth / 2; shifted = false; } } painter->setTransform(baseTransform); }
void MainWindow::updateWindowsExtrasPixmap() { if(QSysInfo::WindowsVersion<QSysInfo::WV_VISTA) return; QRect viewPort; if(!LastActiveSubWindow){ drawWindowsDefaults(); return; } if(activeChildWindow(LastActiveSubWindow) == 1){ LevelEdit* edit = qobject_cast<LevelEdit*>(LastActiveSubWindow->widget()); viewPort = edit->scene->getViewportRect(); }else if(activeChildWindow(LastActiveSubWindow) == 3){ WorldEdit* edit = qobject_cast<WorldEdit*>(LastActiveSubWindow->widget()); viewPort = edit->scene->getViewportRect(); }else{ drawWindowsDefaults(); return; } QPixmap thumbPixmap(viewPort.width(), viewPort.height()); QPixmap livePreviewPixmap(size()); QPainter thumbPainter(&thumbPixmap); QPainter livePreviewPainter(&livePreviewPixmap); if(activeChildWindow(LastActiveSubWindow) == 1){ LevelEdit* edit = qobject_cast<LevelEdit*>(LastActiveSubWindow->widget()); edit->scene->render(&thumbPainter, QRectF(0, 0, viewPort.width(), viewPort.height()), QRectF(viewPort)); edit->scene->render(&livePreviewPainter, QRectF(0, 0, livePreviewPixmap.width(), livePreviewPixmap.height()), QRectF((qreal)viewPort.x(), (qreal)viewPort.y(), (qreal)livePreviewPixmap.width(), (qreal)livePreviewPixmap.height())); }else if(activeChildWindow(LastActiveSubWindow) == 3){ WorldEdit* edit = qobject_cast<WorldEdit*>(LastActiveSubWindow->widget()); edit->scene->render(&thumbPainter, QRectF(0, 0, viewPort.width(), viewPort.height()), QRectF(viewPort)); edit->scene->render(&livePreviewPainter, QRectF(0, 0, livePreviewPixmap.width(), livePreviewPixmap.height()), QRectF((qreal)viewPort.x(), (qreal)viewPort.y(), (qreal)livePreviewPixmap.width(), (qreal)livePreviewPixmap.height())); }else{ drawWindowsDefaults(); return; } if(pge_thumbbar){ pge_thumbbar->setIconicThumbnailPixmap(thumbPixmap); pge_thumbbar->setIconicLivePreviewPixmap(livePreviewPixmap); } }
/*! Ensures cell (\a row, \a column) is visible, scrolling the grid view if necessary. */ void Q3GridView::ensureCellVisible(int row, int column) { QRect r = cellGeometry(row, column); ensureVisible(r.x(), r.y(), r.width(), r.height()); }
void ScrollZoomWidget::UpdateSliderPosition() { QRect sliderRect = GetSliderRect(); zoomSlider->move(sliderRect.x(), sliderRect.y()); zoomSlider->resize(sliderRect.width(), sliderRect.height()); }
void Window::notifyShowNext(NotifyWindow *remove) { if (App::quiting()) return; int32 count = NotifyWindowsCount; if (remove) { for (NotifyWindows::iterator i = notifyWindows.begin(), e = notifyWindows.end(); i != e; ++i) { if ((*i) == remove) { notifyWindows.erase(i); break; } } } uint64 ms = getms(), nextAlert = 0; bool alert = false; for (NotifyWhenAlerts::iterator i = notifyWhenAlerts.begin(); i != notifyWhenAlerts.end();) { while (!i.value().isEmpty() && *i.value().begin() <= ms) { i.value().erase(i.value().begin()); NotifySettingsPtr n = i.key()->peer->notify; if (n == EmptyNotifySettings || (n != UnknownNotifySettings && n->mute <= unixtime())) { alert = true; } } if (i.value().isEmpty()) { i = notifyWhenAlerts.erase(i); } else { if (!nextAlert || nextAlert > *i.value().begin()) { nextAlert = *i.value().begin(); } ++i; } } if (alert) { psFlash(); App::playSound(); } if (cCustomNotifies()) { for (NotifyWindows::const_iterator i = notifyWindows.cbegin(), e = notifyWindows.cend(); i != e; ++i) { int32 ind = (*i)->index(); if (ind < 0) continue; --count; } } if (count <= 0 || !cDesktopNotify()) { if (nextAlert) { notifyWaitTimer.start(nextAlert - ms); } return; } QRect r = psDesktopRect(); int32 x = r.x() + r.width() - st::notifyWidth - st::notifyDeltaX, y = r.y() + r.height() - st::notifyHeight - st::notifyDeltaY; while (count > 0) { uint64 next = 0; HistoryItem *notifyItem = 0; NotifyWaiters::iterator notifyWaiter; for (NotifyWaiters::iterator i = notifyWaiters.begin(); i != notifyWaiters.end(); ++i) { History *history = i.key(); if (history->currentNotification() && history->currentNotification()->id != i.value().msg) { NotifyWhenMaps::iterator j = notifyWhenMaps.find(history); if (j == notifyWhenMaps.end()) { history->clearNotifications(); i = notifyWaiters.erase(i); continue; } do { NotifyWhenMap::const_iterator k = j.value().constFind(history->currentNotification()->id); if (k != j.value().cend()) { i.value().msg = k.key(); i.value().when = k.value(); break; } history->skipNotification(); } while (history->currentNotification()); } if (!history->currentNotification()) { notifyWhenMaps.remove(history); i = notifyWaiters.erase(i); continue; } uint64 when = i.value().when; if (!notifyItem || next > when) { next = when; notifyItem = history->currentNotification(); notifyWaiter = i; } } if (notifyItem) { if (next > ms) { if (nextAlert && nextAlert < next) { next = nextAlert; nextAlert = 0; } notifyWaitTimer.start(next - ms); break; } else { if (cCustomNotifies()) { NotifyWindow *notify = new NotifyWindow(notifyItem, x, y); notifyWindows.push_back(notify); psNotifyShown(notify); --count; } else { psPlatformNotify(notifyItem); } uint64 ms = getms(); History *history = notifyItem->history(); history->skipNotification(); NotifyWhenMaps::iterator j = notifyWhenMaps.find(history); if (j == notifyWhenMaps.end() || !history->currentNotification()) { history->clearNotifications(); notifyWaiters.erase(notifyWaiter); if (j != notifyWhenMaps.end()) notifyWhenMaps.erase(j); continue; } j.value().remove(notifyItem->id); do { NotifyWhenMap::const_iterator k = j.value().constFind(history->currentNotification()->id); if (k != j.value().cend()) { notifyWaiter.value().msg = k.key(); notifyWaiter.value().when = k.value(); break; } history->skipNotification(); } while (history->currentNotification()); if (!history->currentNotification()) { notifyWaiters.erase(notifyWaiter); notifyWhenMaps.erase(j); continue; } } } else { break; } } if (nextAlert) { notifyWaitTimer.start(nextAlert - ms); } count = NotifyWindowsCount - count; for (NotifyWindows::const_iterator i = notifyWindows.cbegin(), e = notifyWindows.cend(); i != e; ++i) { int32 ind = (*i)->index(); if (ind < 0) continue; --count; (*i)->moveTo(x, y - count * (st::notifyHeight + st::notifyDeltaY)); } }
static QRect fixRect(const QRect &r) { return QRect(r.x(), r.y(), r.width() - 1, r.height() - 1); }
void SampleTCOView::paintEvent( QPaintEvent * _pe ) { QPainter p( this ); const QColor styleColor = p.pen().brush().color(); QColor c; if( !( m_tco->getTrack()->isMuted() || m_tco->isMuted() ) ) c = isSelected() ? QColor( 0, 0, 224 ) : styleColor; else c = QColor( 80, 80, 80 ); QLinearGradient grad( 0, 0, 0, height() ); grad.setColorAt( 1, c.darker( 300 ) ); grad.setColorAt( 0, c ); p.setBrush( grad ); p.setPen( c.lighter( 160 ) ); p.drawRect( 1, 1, width()-3, height()-3 ); p.setBrush( QBrush() ); p.setPen( c.darker( 300 ) ); p.drawRect( 0, 0, width()-1, height()-1 ); if( m_tco->getTrack()->isMuted() || m_tco->isMuted() ) { p.setPen( QColor( 128, 128, 128 ) ); } else { p.setPen( fgColor() ); } QRect r = QRect( 1, 1, qMax( static_cast<int>( m_tco->sampleLength() * pixelsPerTact() / DefaultTicksPerTact ), 1 ), height() - 4 ); p.setClipRect( QRect( 1, 1, width() - 2, height() - 2 ) ); m_tco->m_sampleBuffer->visualize( p, r, _pe->rect() ); if( r.width() < width() - 1 ) { p.drawLine( r.x() + r.width(), r.y() + r.height() / 2, width() - 2, r.y() + r.height() / 2 ); } p.translate( 0, 0 ); if( m_tco->isMuted() ) { p.drawPixmap( 3, 8, embed::getIconPixmap( "muted", 16, 16 ) ); } if( m_tco->isRecord() ) { p.setFont( pointSize<7>( p.font() ) ); p.setPen( QColor( 0, 0, 0 ) ); p.drawText( 10, p.fontMetrics().height()+1, "Rec" ); p.setPen( textColor() ); p.drawText( 9, p.fontMetrics().height(), "Rec" ); p.setBrush( QBrush( textColor() ) ); p.drawEllipse( 4, 5, 4, 4 ); } }