public QImage resizeImage(QImage image, QSize newSize) { if (image.size() == newSize) return image; QImage newImage = new QImage(newSize, QImage.Format.Format_RGB32); newImage.fill(new QColor(Qt.GlobalColor.white).rgb()); QPainter painter = new QPainter(newImage); painter.drawImage(new QPoint(0, 0), image); painter.end(); return newImage; }
@Override protected void paintEvent(QPaintEvent event) { QPainter painter = new QPainter(this); painter.save(); painter.drawImage(new QPoint(0, 0), image); painter.restore(); }
@Override protected void paintEvent(QPaintEvent event) { QPainter painter = new QPainter(this); drawWidget(painter); painter.end(); }
private void drawRectangles(QPainter painter) { painter.setPen(QPen.NoPen); for (int i = 1; i < 11; i++) { painter.setBrush(new QColor(0, 0, 255, i * 25)); painter.drawRect(50 * i, 20, 40, 40); } }
private void drawLineTo(QPoint endPoint) { QPainter painter = new QPainter(image); painter.setPen( new QPen( myPenColor, myPenWidth, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap, Qt.PenJoinStyle.RoundJoin)); painter.drawLine(lastPoint, endPoint); modified = true; int rad = (myPenWidth / 2) + 2; update(new QRect(lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad)); lastPoint = endPoint; painter.end(); }
private static QImage makeShade(QImage image, boolean highlight, boolean darker) { double shade_alpha = 0.8; double shade_size = 0.2; double hl_pos = GOLDEN_MEAN; QColor shade_color = QColor.fromRgbF(0, 0, 0, shade_alpha); QColor transparent = darker ? QColor.fromRgbF(0, 0, 0, 0.25) : QColor.fromRgbF(0, 0, 0, 0); QColor hl_color = QColor.fromRgbF(1, 1, 1, 0.7); image = image.copy(); QPainter p = new QPainter(); p.begin(image); p.scale(image.width(), image.height()); QLinearGradient lg = new QLinearGradient(0, 0, 1, 0); lg.setColorAt(0, shade_color); lg.setColorAt(shade_size, transparent); if (highlight) lg.setColorAt(hl_pos, hl_color); lg.setColorAt(1 - shade_size, transparent); lg.setColorAt(1, shade_color); p.fillRect(0, 0, 1, 1, new QBrush(lg)); if (highlight) { QRadialGradient rg = new QRadialGradient(hl_pos, 1 - hl_pos, 0.4, hl_pos, 1 - hl_pos); rg.setColorAt(0, hl_color); rg.setColorAt(1, transparent); p.fillRect(0, 0, 1, 1, new QBrush(rg)); } p.end(); return image; }
public void print() { QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution); QPrintDialog printDialog = new QPrintDialog(printer, this); if (printDialog.exec() == QDialog.DialogCode.Accepted.value()) { QPainter painter = new QPainter(printer); QRect rect = painter.viewport(); QSize size = image.size(); size.scale(rect.size(), Qt.AspectRatioMode.KeepAspectRatio); painter.setViewport(rect.x(), rect.y(), size.width(), size.height()); painter.setWindow(image.rect()); painter.drawImage(0, 0, image); painter.end(); } }
@Override protected void paintEvent(QPaintEvent e) { m_smoke_effect.next(); QPainter p = new QPainter(); p.begin(this); p.fillRect(rect(), new QBrush(QColor.white)); // p.fillRect(rect(), new QBrush(Qt.CrossPattern)); p.drawImage(50, 80, m_logo); p.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform); QImage im = m_smoke_effect.image(); p.drawImage( new QRect(50, -20, im.width(), im.height()), im, new QRect(0, (int) (im.height() * 0.60), im.width(), (int) (im.height() * 0.39))); p.end(); }
private static QImage composeCup(QImage bg_image, QImage fg_image, int size, int warp) { double coffey_alpha = 1; QColor dark_brown = QColor.fromRgbF(0.3, 0.15, 0, coffey_alpha); QColor light_brown = QColor.fromRgbF(0.66, 0.33, 0, coffey_alpha); QColor highlight = QColor.fromRgbF(1, 1, 0.8, coffey_alpha); QColor transparent = QColor.transparent; double highlight_pos = 0.4; double highlight_size = 0.05; QImage combined = new QImage( size + size / 2, size + warp * 2 + size / 8, QImage.Format.Format_ARGB32_Premultiplied); combined.fill(0); QPainter p = new QPainter(); p.begin(combined); p.setRenderHint(QPainter.RenderHint.Antialiasing); p.setPen(Qt.PenStyle.NoPen); // draw the background p.drawImage(0, 0, bg_image); // Draw the coffey QRectF coffey_bounds = new QRectF(0, warp, size, 2 * warp); QConicalGradient cg = new QConicalGradient( coffey_bounds.width() * GOLDEN_MEAN + warp * 0.1, warp * 1.2 + coffey_bounds.height() / 2.0, -30); cg.setColorAt(0, dark_brown); cg.setColorAt(highlight_pos - highlight_size, light_brown); cg.setColorAt(0.4, highlight); cg.setColorAt(highlight_pos + highlight_size, light_brown); cg.setColorAt(1, dark_brown); p.setPen(new QPen(new QBrush(QColor.black), size * 0.01)); p.setBrush(new QBrush(cg)); p.drawEllipse(coffey_bounds); // draw the foreground p.drawImage(0, warp, fg_image); // Draw the handle double handle_dim = size * 0.8; QRectF handle_bounds = new QRectF(size - handle_dim / 2, size / 3, handle_dim, handle_dim); double hcx = handle_bounds.width() / 2; double hcy = handle_bounds.height() / 2; QImage handle_im = new QImage(handle_bounds.size().toSize(), QImage.Format.Format_ARGB32_Premultiplied); { handle_im.fill(0); QPainter ph = new QPainter(); ph.begin(handle_im); QRadialGradient rg = new QRadialGradient(hcx, hcy, hcx, hcx, hcy + size / 30); double ir = 0.5; double or = 0.9; double aa = 0.02; double shade = 0.08; rg.setColorAt(ir - aa, transparent); rg.setColorAt(ir, QColor.fromRgbF(0, 0, 0, 1)); rg.setColorAt(ir + shade, color_green); rg.setColorAt((ir + or) / 2, QColor.fromRgbF(0.8, 0.85, 0.6)); rg.setColorAt(or - shade, color_green); rg.setColorAt(or, QColor.fromRgbF(0, 0, 0, 1)); rg.setColorAt(or + aa, transparent); ph.setBrush(new QBrush(rg)); ph.setPen(Qt.PenStyle.NoPen); ph.drawEllipse(0, 0, (int) handle_bounds.width(), (int) handle_bounds.height()); QLinearGradient lg = new QLinearGradient(0, 0, handle_bounds.width(), 0); lg.setColorAt(0.42, transparent); lg.setColorAt(0.47, QColor.fromRgbF(0, 0, 0)); ph.setBrush(new QBrush(lg)); ph.setCompositionMode(QPainter.CompositionMode.CompositionMode_DestinationIn); ph.drawRect(0, 0, (int) handle_bounds.width(), (int) handle_bounds.height()); ph.end(); } p.drawImage(handle_bounds.topLeft(), handle_im); // The drop shadow... QRadialGradient dsg = new QRadialGradient(0, 0, 0.5, 0, 0); dsg.setColorAt(0, QColor.fromRgbF(0, 0, 0, .75)); dsg.setColorAt(1, transparent); p.translate(size * 3 / 4, size + warp * 1.4); p.scale(size * 1.5, size / 2); p.setBrush(new QBrush(dsg)); p.setPen(Qt.PenStyle.NoPen); p.setCompositionMode(QPainter.CompositionMode.CompositionMode_DestinationOver); p.drawEllipse(new QRectF(-0.5, -0.5, 1, 1)); // p.drawEllipse(new QRectF(size - size / 2, size + warp - size / 2, size, size)); p.end(); return combined; }
private static QImage qtLogoImage(int width, int height, boolean render_logo) { QBrush tt_green = new QBrush(color_green); QBrush tt_black = new QBrush(new QColor(0, 0, 0)); QImage image = new QImage(width, height, QImage.Format.Format_RGB32); QPainter p = new QPainter(); p.begin(image); p.setRenderHint(QPainter.RenderHint.Antialiasing); // Fill the background p.scale(width, height); p.setPen(new QPen(tt_black, 0.05)); p.setBrush(tt_green); p.drawRect(0, 0, 1, 1); if (render_logo) { // set up painter for the logo drawing.. p.setPen(Qt.PenStyle.NoPen); p.setBrush(new QBrush(QColor.black)); p.translate(0.5, 0.5); p.rotate(-45); double thickness = 0.13; double inner_radius = 0.24; double outer_radius = inner_radius + thickness; double ir2 = inner_radius * 2; double or2 = outer_radius * 2; double t_2 = thickness / 2; // draw the black circle QPainterPath circle_path = new QPainterPath(); circle_path.addEllipse(-inner_radius, -inner_radius, ir2, ir2); circle_path.addEllipse(-outer_radius, -outer_radius, or2, or2); p.drawPath(circle_path); QPainterPath t_path = new QPainterPath(); t_path.addRect(-t_2, 0, thickness, 0.48); t_path.addRect(-0.17, -t_2, 0.34, thickness); t_path.setFillRule(Qt.FillRule.WindingFill); p.drawPath(t_path); } p.end(); return image; }
@Override public void paint(QPainter painter, QStyleOptionViewItem option, QModelIndex index) { // if (log.isTraceEnabled()) // log.trace("paint(): index=" + index + ", option.palette().highlight()=" + // option.palette().highlight()); Object data = index.data(); QModelIndex sourceIndex = modelManager.getProxyModel().mapToSource(index); SongRecord songRecord = (SongRecord) ((RecordTableModelManager) modelManager).getRecordForRow(sourceIndex.row()); if (ProfileWidgetUI.instance.getCurrentProfile() instanceof SongProfile) { SongProfile relativeProfile = (SongProfile) ProfileWidgetUI.instance.getCurrentProfile(); QStyle.State state = option.state(); if (RE3Properties.getBoolean("highlight_broken_file_links")) { if (modelManager instanceof RecordTableModelManager) { SearchRecord searchRecord = (SearchRecord) ((RecordTableModelManager) modelManager).getRecordForRow(sourceIndex.row()); if (searchRecord instanceof SongRecord) { SongRecord song = (SongRecord) searchRecord; if (!song.isExternalItem() && !song.hasValidSongFilename()) { if (!state.isSet(QStyle.StateFlag.State_Selected)) { state.set(QStyle.StateFlag.State_Selected); option.setState(state); QPalette p = option.palette(); p.setColor(QPalette.ColorRole.Highlight, BROKEN_FILELINKS_COLOR.getQColor()); option.setPalette(p); } } } } } if (relativeProfile != null) { boolean isMixout = false; float mixoutRating = 0.0f; for (MixoutRecord mixout : relativeProfile.getMixouts()) { if (mixout.getToSongUniqueId() == songRecord.getUniqueId()) { isMixout = true; mixoutRating = mixout.getRatingValue().getRatingNormalized(); break; } } if (isMixout && !(parent instanceof MixoutTableWidget)) { if (!option.state().isSet(QStyle.StateFlag.State_Selected)) { mixoutRating = 0.75f * mixoutRating + 0.25f; Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base)); painter.fillRect( option.rect(), mixoutColor.getLinearGradient(baseColor, mixoutRating).getQColor()); } } else { // target bpm/key/time sig Bpm targetBpm = ProfileWidgetUI.instance.getStageWidget().getCurrentBpm(); if (!targetBpm.isValid()) targetBpm = relativeProfile.getBpmEnd(); if (!targetBpm.isValid()) targetBpm = relativeProfile.getBpmStart(); Key targetKey = ProfileWidgetUI.instance.getStageWidget().getCurrentKey(); if (!targetKey.isValid()) targetKey = relativeProfile.getEndKey(); if (!targetKey.isValid()) targetKey = relativeProfile.getStartKey(); if (parent instanceof CompatibleSongTableWidget) { CompatibleSongTableWidget compatibleWidget = (CompatibleSongTableWidget) parent; if ((compatibleWidget.getShowType() == CompatibleSongTableWidget.COMPATIBLE_TYPE_ALL_HARMONIC) || (compatibleWidget.getShowType() == CompatibleSongTableWidget.COMPATIBLE_TYPE_BPM_ONLY)) { SongKeyRelation keyRelation = SongKeyRelation.getSongKeyRelation(songRecord, targetBpm, targetKey); if (keyRelation.isCompatible()) { float percentInKey = (0.5f - Math.abs(keyRelation.getBestKeyRelation().getDifference())) * 2.0f; if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey); if (!option.state().isSet(QStyle.StateFlag.State_Selected)) { Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base)); painter.fillRect( option.rect(), harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor()); } } } else if (compatibleWidget.getShowType() == CompatibleSongTableWidget.COMPATIBLE_TYPE_KEYLOCK_ONLY) { KeyRelation keyRelation = Key.getClosestKeyRelation( targetBpm.getBpmValue(), songRecord.getStartKey(), targetBpm.getBpmValue(), targetKey); if (keyRelation.isCompatible()) { float percentInKey = (0.5f - Math.abs(keyRelation.getDifference())) * 2.0f; if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey); if (!option.state().isSet(QStyle.StateFlag.State_Selected)) { Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base)); painter.fillRect( option.rect(), harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor()); } } } else if (compatibleWidget.getShowType() == CompatibleSongTableWidget.COMPATIBLE_TYPE_NO_KEYLOCK) { KeyRelation keyRelation = Key.getClosestKeyRelation( songRecord.getStartBpm(), songRecord.getStartKey(), targetBpm.getBpmValue(), targetKey); if (keyRelation.isCompatible()) { float percentInKey = (0.5f - Math.abs(keyRelation.getDifference())) * 2.0f; if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey); if (!option.state().isSet(QStyle.StateFlag.State_Selected)) { Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base)); painter.fillRect( option.rect(), harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor()); } } } } else { if (RE3Properties.getBoolean("enable_harmonic_coloring_in_search_table") && CentralWidgetUI.instance.isDetailsTabOpen()) { SongKeyRelation keyRelation = SongKeyRelation.getSongKeyRelation(songRecord, targetBpm, targetKey); if (keyRelation.isCompatible()) { float percentInKey = (0.5f - Math.abs(keyRelation.getBestKeyRelation().getDifference())) * 2.0f; if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey); if (!option.state().isSet(QStyle.StateFlag.State_Selected)) { Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base)); painter.fillRect( option.rect(), harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor()); } } } } } } } super.paint(painter, option, index); }
protected void drawWidget(QPainter painter) { BurningApp burn = (BurningApp) parent; float width = size().width(); float slid_width = burn.getCurrentWidth(); float step = width / DIVISIONS; float till = (width / MAX_CAPACITY) * slid_width; float full = (width / MAX_CAPACITY) * FULL_CAPACITY; if (slid_width > FULL_CAPACITY) { painter.setPen(yellowColor); painter.setBrush(yellowColor); painter.drawRect(new QRectF(0, 0, full, PANEL_HEIGHT)); painter.setPen(redColor); painter.setBrush(redColor); painter.drawRect(new QRectF(full + 1, 0, till - full, PANEL_HEIGHT)); } else { if (slid_width > 0) { painter.setPen(yellowColor); painter.setBrush(yellowColor); painter.drawRect(new QRectF(0, 0, till, PANEL_HEIGHT)); } } painter.setPen(new QColor(90, 90, 90)); painter.setBrush(QBrush.NoBrush); painter.drawRect(0, 0, size().width() - 1, PANEL_HEIGHT - 1); QFont newFont = font(); newFont.setPointSize(7); painter.setFont(newFont); for (int i = 1; i <= num.length; i++) { painter.drawLine(new QLineF(i * step, 1, i * step, LINE_WIDTH)); QFontMetrics metrics = new QFontMetrics(newFont); int w = metrics.width(num[i - 1]); painter.drawText(new QPointF(i * step - w / 2, DISTANCE), num[i - 1]); } }