void CachedImage::_saveFile(QByteArray* data) const { auto path = _path(); qDebug() << "Saving image from" << _url << "to" << path; if (_man->maxWidth() && _format != UnknownFormat && _format != GifFormat) { auto pic = QImage::fromData(*data); if (pic.width() > _man->maxWidth()) { pic = pic.scaledToWidth(_man->maxWidth(), Qt::SmoothTransformation); QBuffer buffer(data); buffer.open(QIODevice::WriteOnly | QIODevice::Truncate); pic.save(&buffer, _extension.toLatin1().data()); } } QFile file(path); if (file.open(QIODevice::WriteOnly)) { file.write(*data); file.close(); } else qDebug() << "Cannot open file for writing:" << path; delete data; }
QPixmap CMV_PageListProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) { CMV_ELTIMER_START(pixmap); auto img = currentBook->getPageData(id); auto imgScaled = img.scaledToWidth(CMV_DeviceInfo::instance().screenWidth() / 5, Qt::SmoothTransformation); QPixmap pix(imgScaled.size()); QPainter painter(&pix); painter.drawImage(QPoint{0,0},imgScaled); CMV_ELTIMER_STOP(pixmap); return pix; }
// static QCursor MapEditorTool::scaledToScreen(const QCursor& unscaled_cursor) { auto scale = Settings::getInstance().getSetting(Settings::General_PixelsPerInch).toReal() / 96.0; if (unscaled_cursor.shape() == Qt::BitmapCursor && scale > 1.5) { // Need to scale our low res image for high DPI screen const auto unscaled_pixmap = unscaled_cursor.pixmap(); const auto scaled_hotspot = QPointF{ unscaled_cursor.hotSpot() } * scale; return QCursor{ unscaled_pixmap.scaledToWidth(unscaled_pixmap.width() * scale, Qt::SmoothTransformation), qRound(scaled_hotspot.x()), qRound(scaled_hotspot.y()) }; } else { return unscaled_cursor; } }
void SeparateTabBar::mouseMoveEvent (QMouseEvent *event) { if (isMovable ()) { QTabBar::mouseMoveEvent (event); return; } if (!(event->buttons () & Qt::LeftButton)) return; if ((event->pos () - DragStartPos_).manhattanLength () < QApplication::startDragDistance ()) return; const int dragIdx = tabAt (DragStartPos_); auto widget = TabWidget_->Widget (dragIdx); auto itw = qobject_cast<ITabWidget*> (widget); if (!itw) { qWarning () << Q_FUNC_INFO << "widget at" << dragIdx << "doesn't implement ITabWidget"; return; } auto px = QPixmap::grabWidget (widget); px = px.scaledToWidth (px.width () / 2, Qt::SmoothTransformation); auto idt = qobject_cast<IDNDTab*> (widget); auto data = new QMimeData (); if (!idt || QApplication::keyboardModifiers () == Qt::ControlModifier) { data->setData ("x-leechcraft/tab-drag-action", "reordering"); data->setData ("x-leechcraft/tab-tabclass", itw->GetTabClassInfo ().TabClass_); } else if (idt) idt->FillMimeData (data); auto drag = new QDrag (this); drag->setMimeData (data); drag->setPixmap (px); drag->exec (); }