Commit de0314b0 authored by Alexandre Lision's avatar Alexandre Lision

ui: better photos

enable high antialising and smoother scaling

Change-Id: Icfa99994abfd1ddb1b7311b2bf419102fb56645b
parent 266fca0e
...@@ -172,7 +172,7 @@ NSInteger const CALL_BUTTON_TAG = 400; ...@@ -172,7 +172,7 @@ NSInteger const CALL_BUTTON_TAG = 400;
NSImageView* photoView = [result viewWithTag:IMAGE_TAG]; NSImageView* photoView = [result viewWithTag:IMAGE_TAG];
Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object)); Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object));
QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(35,35)); QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(40,40));
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))]; [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
[((ContextualTableCellView*) result) setContextualsControls:[NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]]]; [((ContextualTableCellView*) result) setContextualsControls:[NSMutableArray arrayWithObject:[result viewWithTag:CALL_BUTTON_TAG]]];
...@@ -194,7 +194,6 @@ NSInteger const CALL_BUTTON_TAG = 400; ...@@ -194,7 +194,6 @@ NSInteger const CALL_BUTTON_TAG = 400;
- (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item - (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item
{ {
QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)]; QModelIndex qIdx = [treeController toQIdx:((NSTreeNode*)item)];
HoverTableRowView* result = [outlineView makeViewWithIdentifier:@"HoverRowView" owner:nil]; HoverTableRowView* result = [outlineView makeViewWithIdentifier:@"HoverRowView" owner:nil];
if(!qIdx.parent().isValid()) { if(!qIdx.parent().isValid()) {
[result setHighlightable:NO]; [result setHighlightable:NO];
......
...@@ -221,7 +221,7 @@ NSInteger const TXT_BUTTON_TAG = 500; ...@@ -221,7 +221,7 @@ NSInteger const TXT_BUTTON_TAG = 500;
[displayName setStringValue:qIdx.data(Qt::DisplayRole).toString().toNSString()]; [displayName setStringValue:qIdx.data(Qt::DisplayRole).toString().toNSString()];
NSImageView* photoView = [result viewWithTag:IMAGE_TAG]; NSImageView* photoView = [result viewWithTag:IMAGE_TAG];
Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object)); Person* p = qvariant_cast<Person*>(qIdx.data((int)Person::Role::Object));
QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(35,35)); QVariant photo = GlobalInstances::pixmapManipulator().contactPhoto(p, QSize(40,40));
[photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))]; [photoView setImage:QtMac::toNSImage(qvariant_cast<QPixmap>(photo))];
return result; return result;
} }
......
...@@ -44,16 +44,18 @@ namespace Interfaces { ...@@ -44,16 +44,18 @@ namespace Interfaces {
} }
QVariant ImageManipulationDelegate::contactPhoto(Person* c, const QSize& size, bool displayPresence) { QVariant ImageManipulationDelegate::contactPhoto(Person* c, const QSize& size, bool displayPresence) {
const int radius = (size.height() > 35) ? 7 : 5; const int radius = size.height() / 2;
QPixmap pxm; QPixmap pxm;
if (c && c->photo().isValid()) { if (c && c->photo().isValid()) {
QPixmap contactPhoto((qvariant_cast<QPixmap>(c->photo())).scaledToWidth(size.height()-6)); QPixmap contactPhoto(qvariant_cast<QPixmap>(c->photo()).scaledToWidth(size.height(),
Qt::TransformationMode::SmoothTransformation));
pxm = QPixmap(size); pxm = QPixmap(size);
pxm.fill(Qt::transparent); pxm.fill(Qt::transparent);
QPainter painter(&pxm); QPainter painter(&pxm);
//Clear the pixmap //Clear the pixmap
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
painter.setCompositionMode(QPainter::CompositionMode_Clear); painter.setCompositionMode(QPainter::CompositionMode_Clear);
painter.fillRect(0,0,size.width(),size.height(),QBrush(Qt::white)); painter.fillRect(0,0,size.width(),size.height(),QBrush(Qt::white));
painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
...@@ -62,20 +64,17 @@ namespace Interfaces { ...@@ -62,20 +64,17 @@ namespace Interfaces {
QRect pxRect = contactPhoto.rect(); QRect pxRect = contactPhoto.rect();
QBitmap mask(pxRect.size()); QBitmap mask(pxRect.size());
QPainter customPainter(&mask); QPainter customPainter(&mask);
customPainter.setRenderHint (QPainter::Antialiasing, true ); customPainter.setRenderHints (QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
customPainter.fillRect (pxRect , Qt::white ); customPainter.fillRect (pxRect , Qt::white );
customPainter.setBackground (Qt::black ); customPainter.setBackground (Qt::black );
customPainter.setBrush (Qt::black ); customPainter.setBrush (Qt::black );
customPainter.drawRoundedRect(pxRect,radius,radius); customPainter.drawRoundedRect(pxRect,radius,radius);
contactPhoto.setMask(mask); contactPhoto.setMask (mask );
painter.drawPixmap(3,3,contactPhoto); painter.drawPixmap (0,0,contactPhoto );
painter.setBrush(Qt::NoBrush); painter.setBrush (Qt::NoBrush );
painter.setPen(Qt::white); painter.setPen (Qt::black );
painter.setRenderHint (QPainter::Antialiasing, true ); painter.setCompositionMode (QPainter::CompositionMode_SourceIn);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn); painter.drawRoundedRect(0,0,pxm.height(),pxm.height(),radius,radius);
painter.drawRoundedRect(3,3,pxm.height()-6,pxm.height()-6,radius,radius);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
} }
else { else {
pxm = drawDefaultUserPixmap(size, false, false); pxm = drawDefaultUserPixmap(size, false, false);
...@@ -127,19 +126,38 @@ namespace Interfaces { ...@@ -127,19 +126,38 @@ namespace Interfaces {
QPixmap ImageManipulationDelegate::drawDefaultUserPixmap(const QSize& size, bool displayPresence, bool isPresent) { QPixmap ImageManipulationDelegate::drawDefaultUserPixmap(const QSize& size, bool displayPresence, bool isPresent) {
const int radius = size.height() / 2;
QPixmap pxm(size); QPixmap pxm(size);
pxm.fill(Qt::transparent); pxm.fill(Qt::transparent);
QPainter painter(&pxm); QPainter painter(&pxm);
painter.setCompositionMode(QPainter::CompositionMode_Clear);
painter.fillRect(0,0,size.width(),size.height(),QBrush(Qt::white));
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
// create the image somehow, load from file, draw into it... // create the image somehow, load from file, draw into it...
auto sourceImgRef = CGImageSourceCreateWithData((CFDataRef)[[NSImage imageNamed:@"NSUser"] TIFFRepresentation], NULL); auto sourceImgRef = CGImageSourceCreateWithData((CFDataRef)[[NSImage imageNamed:@"NSUser"] TIFFRepresentation], NULL);
auto imgRef = CGImageSourceCreateImageAtIndex(sourceImgRef, 0, NULL); auto imgRef = CGImageSourceCreateImageAtIndex(sourceImgRef, 0, NULL);
auto finalImgRef = resizeCGImage(imgRef, size); auto finalpxm = QtMac::fromCGImageRef(resizeCGImage(imgRef, size));
painter.drawPixmap(3,3,QtMac::fromCGImageRef(finalImgRef));
QRect pxRect = finalpxm.rect();
QBitmap mask(pxRect.size());
QPainter customPainter(&mask);
customPainter.setRenderHint (QPainter::Antialiasing, true );
customPainter.fillRect (pxRect , Qt::white );
customPainter.setBackground (Qt::black );
customPainter.setBrush (Qt::black );
customPainter.drawRoundedRect(pxRect,radius,radius);
finalpxm.setMask(mask);
painter.setRenderHint (QPainter::Antialiasing, true );
painter.drawPixmap(0,0,finalpxm);
painter.setBrush(Qt::NoBrush);
painter.setPen(Qt::black);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawRoundedRect(0,0,pxm.height(),pxm.height(),radius,radius);
CFRelease(sourceImgRef); CFRelease(sourceImgRef);
CFRelease(imgRef); CFRelease(imgRef);
CFRelease(finalImgRef);
return pxm; return pxm;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment