Qt WebView and clicking on a google map - qt

Has anyone tried to click on a google map displayed in Qt QWebView via one of QWebView's mouse event methods? I want to do this in this way becouse I need to run some actions both in Qt and in google map (when I click on map I want to add e. g. a bus stop - it'll load inside the programme and the marker will apear on the map). I've got a method for adding a placemark and I know I can call it, but I've got problem with passing correct position.
void MyWebView::mousePressEvent(QMouseEvent * e) {
QString command = "placeMarker(new google.maps.LatLng(";
command.append(new QString(e->x()));
command.append(", ");
command.append(QString(e->y()));
command.append("))");
this->page()->mainFrame()->evaluateJavaScript(command);
}

Related

How do I replicate the gtk_button_click function in GTK4

All,
As I continue to learn how to migrate code I built for GTK3 to GTK4, I continue to encounter instances where functions in GTK3 no longer exist in GTK4. As an example, I had built a small test program that uses a standard button with an image to launch the color chooser instead of using directly presenting a GTK color button. This was done for aesthetics. The method I used was having both a GTK color button that was not visible along with a standard button with an image. Within the program I connected the "button click" signal to function "on_buttoncolor_clicked" to the standard button. Following is the simple code within that function that then emits a "button click" signal for the color button.
void on_buttoncolor_clicked (GtkButton *b)
{
gtk_button_clicked(GTK_BUTTON(button));
}
When I ported this over and attempted to compile this program with the GTK4 libraries, the compilation erred out indicating that this function was not found.
To get around this, I had attempted to attach an image to the GTK color button, but that produced spurious errors when clicking on the button. So, I would like to be able to replicate the "gtk_button_clicked" function. Any advice on this would be appreciated. FYI, I am attaching a small image of how the GTK3 version of the user interface looks like.
Regards,
Craig
All,
I did attempt to replicate sending a "button click" signal to the color button using the "g_signal_emit" function, but that signal was unknown to the color button.
After digging into the source code for the color button widget, I determined that a "button click" signal does get attached to a button element that is a part of the "GtkColorButton" structure. So, I directed the "g_signal_emit" function at the "button element" within the structure by revising my code.
First, I cloned the structure for the "GtkColorButton" widget which gave me access to the structure.
struct _GtkColorButton {
GtkWidget parent_instance;
GtkWidget *button;
GtkWidget *swatch;
GtkWidget *cs_dialog;
char *title;
GdkRGBA rgba;
guint use_alpha : 1;
guint show_editor : 1;
guint modal : 1;
};
Then, I revised the signal connection to use "g_signal_connect_swapped" to reference the color button to the signal.
g_signal_connect_swapped (button "clicked",
G_CALLBACK (on_button_clicked), buttoncolor);
Next, I revised the signal emission function to be directed at the button element within the "GtkColorButton" widget.
void on_button_clicked (GtkColorButton *b)
{
g_signal_emit (b->button,
g_signal_lookup ("clicked", G_OBJECT_CLASS_TYPE
(GTK_WIDGET_GET_CLASS(GTK_BUTTON(button)))), 0);
}
This resulted in the expected color selection dialog appearing when the standard label button is clicked as noted in the newly attached image.
With this resolution, I believe that this issue can be closed.
Regards,
Craig

click event listener on styled map icons and labels

Is it possible to add a listener for the click event on the icons and/or labels that appear for styled maps? I have a form that allows entry of Points of Interest. Since the poi styling shows icons and/or labels for many potential candidates, and clicking on one opens an infowindow with address info, etc, I would like to capture this address info to the fields on my form if the user clicks on one.
There is no API-based access to the POI's .
But there is a possible workaround.
When you click on a POI an InfoWindow opens. It's possible to modify the InfoWindow-prototype to be able to access the content of the InfoWindow without having a reference to the InfoWindow-instance.
//store the original setContent-function
var fx = google.maps.InfoWindow.prototype.setContent;
//override the built-in setContent-method
google.maps.InfoWindow.prototype.setContent = function (content) {
//when argument is a node
if (content.querySelector) {
//search for the address
var addr = content.querySelector('.gm-basicinfo .gm-addr');
if (addr) {
alert(addr.textContent);
//leave the function here
//when you don't want the InfoWindow to appear
}
}
//run the original setContent-method
fx.apply(this, arguments);
};
Demo: http://jsfiddle.net/doktormolle/Vkf43/
Note: The selectors for the infowindow are not documented, they may change in the future
I realize this is an old Q, but this was recently fixed in Maps API. You can now listen for click events on map icons.
Starting with version 3.26 you should listen to the "click" event on the Map object. If the user clicks on a POI, a IconMouseEvent is raised. This class extends the Regular MouseEvent and contains a property called placeId. So you can check if the event object has defined placeId. The placeId field contains of course a Place Id, that you can use with Places API to get more info on the icon that was clicked. Calling stop() on the event itself will prevent Maps API from showing the default info window.
I prepared a small demo which demonstrates how to capture the click event and display your own info window.
http://jsbin.com/parapex/edit?html,output

Next and previous control button in winAPI to go to next page (c++)

I am creating an winAPI application in c++ I have a photo in preview pane and I want to create two buttons NEXT and PREVIOUS on clicking them I will go to the next page .
Could you please give me the idea how to do that in c++ ??
Do I need to use QT libraray or it can be done using the in built function of WinAPI like -
HWND hwndButton1 = CreateWindow(L"BUTTON",L"NEXT",WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,550,800,100,30,m_hwndPreview,(HMENU)buttonid1,(HINSTANCE)GetWindowLong(m_hwndPreview, -6),NULL);
HWND hwndButton2 = CreateWindow(L"BUTTON",L"PREVIOUS",WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,650,800,100,30,m_hwndPreview,(HMENU)buttonid2,(HINSTANCE)GetWindowLong(m_hwndPreview, -6),NULL);
and then using WM_COMMAND for both the button clicks.
Am I going right?
I just want my API application work like a .pdf extension file...as in PDF files we have up and down arrow and on clicking upon them we can go to the next page..In winAPIc++ I couldn't find any such arrow function.. please tell me if there is any such arrow up/down function present to go to next page (because I am very less interested in creating NEXT and PREVIOUS button using createwindow function.. It looks odd).
You have not mentioned what tools you are using, so we don't know if you have a resouce editor. You should research that in a forum appropriate for the tools. If you think writing one line of code to create a button is "very complicated" then you need a better tool.
If you do not want the buttons to appear on top of the picture then you need another place to put them. One common possibility is a toolbar. It is a strip for buttons along the top or bottom of the main window:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb760435(v=vs.85).aspx
With a resource editor you can draw an arrow on the button. Without a resource editor you can set the button text to a unicode arrow:
SetWindowText(hwndButton1, L"\x25bc"); // down arrow, use 25b2 for up arrow
Most buttons (and other controls) are created using a resource editor, placing the controls on a dialog template or a toolbar resource. If you do that Windows will create the buttons when you create the dialog or toolbar. This method is much preferred because Windows will adjust the size of the buttons as required for the screen settings in use.
If you can't do that you must use CreateWindow as you are doing.
Finally it is done.. I have created the buttons neither using Qt or nor using any createWindowEx..The best and easy approach to follow is resource editor ...just put some button on dialog and use IDD_MAINDIALOG (in my case)
m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this);
and then
BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam)
{
switch(Umsg) // handle these messages
{ .........
}
....
}
and thats done. Very easy task.

QtWebKit: How can I detect a URL changed via the HTML5 history API

We're currently using QtWebKit to build an application, part of which displays the product catalogue page of our website. On that webpage we're using the jQuery.history plugin to keep track of sorting and filtering options without users needing to reloading the page.
When jQuery.history's pushState() function is called the URL provided is pushed to the history properly, but QWebView's urlChanged() signal (which we're listening for to update back/forward buttons and the address bar) isn't fired even though the current URL has changed. I can only assume this is because no link was clicked, nor was there a page reload so Qt doesn't think it needs to do anything URL-related.
Is there any way to detect a URL change made via the HTML5 history API in QtWebKit, or am I missing something obvious?
There is QWebPage::saveFrameStateRequested signal:
This signal is emitted shortly before the history of navigated pages in frame is changed, for example when navigating back in the history.
You can use it to track history changes:
void MainWindow::saveFrameStateRequested(QWebFrame *frame, QWebHistoryItem *item) {
// this slot is executed before the history is changed,
// so we need to wait a bit:
QTimer::singleShot(100, this, SLOT(listHistoryItems()));
}
void MainWindow::listHistoryItems() {
for (QWebHistoryItem historyItem: view->page()->history()->items()) {
qDebug() << "item" << historyItem.url() << historyItem.title();
}
}
void MainWindow::finishLoading(bool) {
// (re)connect the signal to track history change,
// maybe there is a better place to connect this signal
// where disconnect won't be needed
disconnect(view->page(), SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)),
this, SLOT(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)));
connect(view->page(), SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)),
this, SLOT(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)));
}
The modified Fancy Browser example screenshot.

How to embed "Share on Facebook" button into Flex application?

I'm trying to duplicate the behaviour of the "Share on Facebook" button from Youtube. Basically, inside a Flex app I'll have a button and when I click it I want a popup that enables me to post something on the wall.
While it is possible to make a call to javascript to open the pop-up I want to be able to set the images and the text of my posting.
Do you know how I could set the images or text as a paramter to the sharer window?
Thank you!
This is fairly straightforward to do. Youtube uses the Facebook API which pops up a new window (Info on Facebook sharer API).
To do this in flex,
Create a button that onClick will call a javascript method, ExternalInterface.call("fbLink", "www.yahoo.com");
In your HTML file (most likely index.template.html) add the JavaScript method, fbLink which does the following:
function fbLink(url) {
window.popup("http://www.facebook.com/sharer.php?u=" + url, {height:440, width:620, scrollbars:true})
}
Now when a user clicks on the button they will be sharing the link "yahoo.com" with facebook account.
as I understood you asking for some help in accessing js popup in html page of facebook share button, so you should use ExternalInterface in this casa and access needed DOM node using getElementById function in your js interface.
In other case I want propose you to read another one way http://www.riaxe.com/blog/flex/publish-into-facebook-wall-from-flex/
It seems that you want to have a button on the flash application and once clicked it opens the facebook page that shares the video/image that pertains to the clicked button. What you want to do is simply create a button that on click opens a new website to facebook using their share api which has the following format:
var facebookShare:String = "http://www.facebook.com/share.php?u=' + encodedVideoLink + '&t='+ encodedVideoText";
Where the u parameter stands for the link that you wish to share, and the t parameter stands for the title of the piece that you want to share, whether it be a picture or video.
You want to add an event listener on MouseEvent.CLICK that has as its callback function a method that handles the opening of the facebook page passing the facebookShare variable as shown above. To open another page on your browser you can use this AS3 Class called URLNavigator: http://www.danishmetal.dk/project/source/com/zorked/URLNavigator.as
To sum it up, something along these lines would do:
var facebookShare:String = "http://www.facebook.com/share.php?u=' + encodedVideoLink + '&t='+ encodedVideoText";
facebookButton.addEventListener(MouseEvent.CLICK, this._goToUrl(facebookShare));
private function _goToUrl(link:String):Function {
var window:String = "_blank",
feats = "",
thisOverlay:Object = this; // to not lose scope when returning a func
return function (e:MouseEvent):void {
trace("Opening link to:"+link);
try { URLNavigator.ChangePage(link, window, feats); }
catch (e:Error) { trace("error launching "+link+" in "+window+" with feature set "+feats); }
}
}
I hope that helps. If you have questions regarding the code please let me know.

Resources