Display only bounding box during dragging objects not the whole object (Fabric.js) - draggable

I am using fabric js and I only need to display the bounding box of an Object, not the whole object during dragging. Means to say Object would be fixed until I stops the dragging.

I think you can inherite your own subclass from object with custom property "isMoving" or "isSelected", and implement _render function with if statement - call default _render or draw only bounding box somehow (for example try set transparency for object to 0). For canvas on "object:selected" or "object:moving" set "isMoving" true, and for "selection:clear" set to false.

Related

GUI shapes border checking (FLOWCHART CONNECTOR)

So I'm working on a Flowchart (OOP) Program, and I have to implement a code for Connector, which has the condition that it must be between 2 other shapes.
So the question here is how to check if the user click is within a "shape" area ?
Like I can "GetMouseClick" as a function, but I need to check if this point lies in a shape from the shapes drawn.
NOTE : Each shape has a class !
For each class (shape) define a getBounds(...) method that will return the rectangle (or a polygon) and when you click you can iterate over all shapes and see within what bounds the click was.
Another idea is to add mouse listener for each shape and rely on event handler to tell you what shape was clicked.

Qt QScrollBar setValue() method doesn't work

I'm implementing a image viewer based on the Image Viewer example (http://doc.trolltech.com/4.7-snapshot/widgets-imageviewer.html)
But I'm using the design mode for the interface.
A QLabel inside a QScrollBar QScrollArea. The image appears, but when I zoom, the bars never appear.
I found out the setValue() method -used in adjustScrollBar() method- from each scrollBar, never modifies its value (it's always 0).
If that value was greather than 0, the bar would appear. In the original example, it does.
What am I missing in UI designer??
Thanks.

xcode: drawing objects in catiledlayer

I'm trying to draw my own objects to a CATiledLayer, im just not sure how i should push the objects to context that is used in drawLayer. For example i know that i can add the text i want to draw on the screen by declaring the text code inside the method drawLayer, however say that i want to draw something only when i get a user input, then i would like to create this new text object and draw it to the screen, but i'm not sure how i would do this outside the drawLayer method since i need the context.
If you want the layer to redraw it's contents you send it a setNeedsDisplay message. Then you can draw your additional objects.

How can I change individual cell background colors in an NSForm?

I would like to individually set cell background colors in an NSForm. I thought it would be a matter of subclassing NSForm and overriding -drawCellAtRow:column:. But -drawCellAtRow:column: only gets called when the cell receives focus.
I've experimented with calling -setCellBackgroundColor on the NSForm but that changes the title background, not the value.
Is there an approach I'm not finding?
I think this just isn't possible with NSFormCell.
First thing I tried:
self.form.drawsCellBackground = YES;
self.form.cellBackgroundColor = [NSColor redColor];
This appears to draw the background only behind the label. Some further testing suggested that a single NSFormCell spans both the label and text field, and the background was drawing behind both. When the text field draws on top, its own background covers up the red color.
Next I subclassed NSFormCell. The only method to be called is -drawWithFrame:inView:. The frame, again, spans both the label and text field. The control view is the NSForm. If I draw my own background and then invoke [super drawWithFrame:inView:], it appears just as above, visible behind the label, but not visible behind the text field. If I invoke super and then draw the background, it appears atop both.
NSFormCell's implementation does not invoke -drawInteriorWithFrame:inView: nor does it seem to provide another override point.
I tried setting highlighted, and implementing -highlightColorWithFrame:inView: – same issue.
While I was trying to understand how this all worked I also tried subclassing NSForm. The only drawing-related method called is -drawRect:. These methods are never invoked: -drawCellAtIndex:, -drawCellAtRow:column:, -drawCell:, -drawCellInside:.
Apart from getting Apple to fix this, the only solutions I see are trying to use NSForm's superclass NSMatrix, or just using labels and text fields.

What is the best way to make a QTableView's cells have up and down button pushed states in Qt?

I'm trying to make the cells of a QTableView look like 3D clickable buttons. So that when you click on a cell, the button looks pushed. Everyone seems to think I merely want to change the colour, I need to show images of a normal button, and a pushed button, that look 3-dimensional.
I have done this already with calling QTableView::setItemDelegate(), with an appropriate ItemDelegate that will change the background of the cell when it's clicked. However I'm stuck at this point because I want some cells to be different coloured buttons based on the data they contain. So a cell with a low number would be a red button, that's also red when it's clicked, and the other cells would be different colours.
I can set the colour of the button with the TableModel, but once the button is clicked, there is no way for the ItemDelegate to know that it's supposed to be a different colour than the rest. How can you link the two so the ItemDelegate knows what colour it's supposed to be?
Also, is there simply a better way to make cells look like buttons?
You can call QModelIndex::model() from within the ItemDelegate's paint() method, since it has a QModelIndex parameter. This gives you the TableModel for the data, which you can programatically decide what colour the cell's button will be.
However, this is still not as elegant as I'd hope. Does anyone know a better way to change the appearance of table cells when in both the up and down button push states?
Why don't you asked the index for the background color.
Something like this ...
QStyleOptionToolButton buttonOption;
const QStyleOptionViewItemV4& optionV4 = dynamic_cast<QStyleOptionViewItemV4&>(option);
//...
buttonOption.palette.setBrush( QPalette::Button, index.data( Qt::BackgroundColorRole ) );
//...
I have feeling that its a bug in Qt and its must have been ...
// model code
if(role==Qt::BackgroundColorRole )
return qvariant_cast<QBrush>( QBrush(Qt::red) );
// delegate code
buttonOption.palette.setBrush(QPalette::Button, optionV4.backgroundBrush );
Because the optionV4.backgroundBrush is correct in the sizeHint method but is invalid in the paint method . I see now reason why the sizeHint should have the background brush and the paint method not. I'll report it to Nokia.
EDIT:
Looks like I was right and its a bug in < Qt4.5.
QStyleOptionViewItemV4 doesn't copy the icon and backgroundBrush
Can you not get the ID/row count of the table cell's row and then check it against the colour table that you may be having, and set the colour accordingly? I am not sure if I understood your question well or not.
Assign a data role for the background color, and in your item delegate, ask the model index what it's background color is (using data( bg_color_role ) or something similar). Then, in your model, you need to make sure the data function returns a color for the bg_color_role that is appropriate for the data being modeled.
The way to do that is to use the data method of the QModelIndex object you get on the paint method, and ask for a specific role (if you define a custom model, you can add your own roles, and give the information you need to the delegate in those roles.)
TimW, I think you have to fill the QStyleOptionViewItemV4 info by calling initStyleOption before.
I'm not sure where the requirement for a background image comes from. If you want the cells to look like QPushButtons, you should probably inherit from QItemDelegate and implement paint() to use QStyle to draw you a QPushButton, something like this:
QStyleOptionButton opt;
// fill 'opt' from the information from the model, and the style option that's passed in
style()->drawControl( QStyle::CE_PushButton, &opt, painter );
Have you tried using custom style sheets?
You could just apply the same stylesheet to every cell, and then change the background image / style to draw the 3D button images depending on whether or not it's selected.

Resources