Rotation of the screen (displayDirection) in the cascades (QtQuick) app

Hi all

I am new to BB, but have Qt / Qt Quick experience.

I'm trying to transfer my Qt Quick to BB10 application. The app is SmartCam: http://sourceforge.net/projects/smartcam/

I use camera APIs but without waterfalls. I have problems with the viewfinder of the camera and the orientation of my user interface.

I demand BB10 to support orientation to landscape for my application like this:

(1) in bar - descriptor.xml:

    
        landscape
        false
        none
        false
    

(2) in main.cpp:

    QmlApplicationViewer qmlViewer;
 qmlViewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape); // ORIENTATION

It of OK, my application starts in the landscape and does not turn into the portrait when the orientation of the device changes (in fact many times the application started in portrait but only 0.5%; this isn't my main problem).

My problem is that even if it begins in the landscape, the displayDirection (the name of it comes from the OrientationSupport class cascades) is sometimes different: sometimes the text of the Blackberry logo displayed briefly when my application starts is up (80%) and sometimes she is facing down (20%).

I need to specify an angle with the viewfinder of the camera according to the value of the displayDirection (90 degrees or 270) but I have no way I know of to question the value of this setting, because the waterfalls of OrientationSupport is not available for Qt Quick application, it's me linking errors:

undefined reference to `bb::cascades::OrientationSupport::instance()'

I added this in the .pro file:

LIBS += -lcamapi -lscreen -lbtapi -ljpeg -lbps

but nothing helped.

The RotationCamera example also uses the class OrientationSupport is not a big help for me.

I tried also in main.cpp:

    // Disable screen power down
    int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
    WId winId = glWidget->winId();
    screen_set_window_property_iv(screen_window_t(winId), SCREEN_PROPERTY_IDLE_MODE, &idle_mode);
    int angle = 0;
    screen_set_window_property_iv(screen_window_t(winId), SCREEN_PROPERTY_ROTATION, &angle);
    winId = qmlViewer.winId();
    screen_set_window_property_iv(screen_window_t(winId), SCREEN_PROPERTY_ROTATION, &angle);

But the definition of SCREEN_PROPERTY_ROTATION did not help either...

Because of this problem that my app was rejected form the AppWorld.

Can anyone help?

Thank you

Ionut

Fixed it by calling

navigator_set_orientation(NAVIGATOR_LEFT_UP, NULL);

in response to the event of bps navigator: NAVIGATOR_WINDOW_ACTIVE

This way my app always starts in the landscape (what was going on as before) but the display direction will be constant at startup.

Tags: BlackBerry Developers

Similar Questions

  • Rotation of the screen with Automator and a script

    I have no knowledge whatsoever about scripts, coding or automator. I continue to read discussions about the issue, but I don't understand them. It would be a great help for me if someone please explain how to create a kind of keyboard shortcut that changed the rotation of the screen (the own macbook screen, not an external) using automator and a script on a Macbook Air running OS X El Capitan 10.11.2.

    Is this possible?

    Thank you in advance.

    One option is to use the utility command line fb - turn in Automator service and assign a keyboard shortcut. Download the GitHub source fb-rotation, compilation, following the indications on GitHub and output the binary to usr; or download a binary compiled and move to usr/local/bin.

    Create an Automator service, set the options "Service receives no entry in any application", add an action to run the Shell Script and set the options as "Shell: / bin/bash ', ' Pass entry: to stdin.  Type the command rotation fb for the desired degree of orientation of the screen such as ' / usr/local/bin/fb-rotation - d 0 - r 180 ' 180 ° on the main screen. Register the service under a name.

    Go to  > System Preferences > keyboard > shortcuts > Services. Highlight the service you created, select it, click "none" and create a shortcut using a unique combination of keys. Create separate services of Automator for the additional screen orientations. Quit the system preferences when you are finished.

    Tested with OS X 10.10.5 Yosemite and El Capitan 10.11.3

  • Why has my Automatic rotation of the ipad stopped when I pass the vertical horizontal screen remains in the vertical position?

    Why has my Automatic rotation of the ipad stopped when I pass the vertical horizontal screen remains in the vertical position?

    Not all applications are supported both orientations. If you experience of this with an app that should work, you know, you most likely locked up the switch of direction. Drag your finger from the bottom of the screen bezel to display Control Center. Tap on the lock with a circular arrow icon.

  • Set the rotation of the screen to external monitor on Portege M400

    I would like to be able to use the screen of the mobile phone in the form of tablets, while the display to an external monitor. The problem is that when you use the laptop in its Tablet configuration (fixed and swivel screen on top) the external monitor displays the image upside down. If I rotate the screen image output, so I use the Tablet upside which is impossible when it is docked. Is it all the same independently set the rotation of the screen of the Tablet and the external screen?
    If someone could help me with this I would be grateful as at this moment whether or not I have to remove the Tablet and use backwards the external monitor.

    I use Windows tablet PC on a Portege M400 and a monitor external 22 "LCD

    Thank you.

    Before we start the discussion I just have one question: do you want to use extended desktop or office cloned on external monitor?

  • My screen has rotated to the left. How can I get that standing back?

    Believe it or not, my screen now a normal rotation on the left side at the bottom of the screen. How do this directly again? Help!

    Normally, you just click on Ctrl + Alt + TOP or button.

    See you soon.

    Mick.

  • Unable to detect the rotation of the device of the method of sublayout of screen

    I'm developing an application compiled for OS 4.5. I need to find a way to detect the rotation of the unit and again fill the screen so that the fields are arranged according to the new dimensions.

    My idea was to save the display width and height in some private variables in my case screen and method of sublayout overloaded screen, check if the new values have been changed.

    What happens is that I get the old width and height again and again.

    I first read this post. In this document, @arkadyz points out how the order of the calls is a little weird and values returned by the view class are updated after sublayout is finished.  Therefore, there is no way to detect by the sublayout method.

    The proposed solution is to check the dimensions of the display within an invokeLater. Here's my test code:

    public class TestScreen extends MainScreen {
    
        public TestScreen(){
            super(Manager.NO_VERTICAL_SCROLL);
            populateScreem();
        }
    
        private void populatescreen(){
            deleteAll();
            //fields and containers added here. No need to add any to observe the issue.
        }
    
        public void sublayout(int width, int height){
            super.sublayout(width,height); //Tried calling this in the last line as well with identical result.     
    
            System.out.println(">>>>>>>>> Display.getWidth(before): " + Display.getWidth());
            System.out.println(">>>>>>>>> Display.getOrientation(before): " + Display.getOrientation());
            System.out.println(">>>>>>>>> Width argument value (before): " + width);
    
            UiApplication.getUiApplication().invokeLater(new Runnable(){
                public void run() {
    
                    System.out.println(">>>>>>>>> Display.getWidth(later): " + Display.getWidth());
                    System.out.println(">>>>>>>>> Display.getOrientation(later): " + Display.getOrientation());
                }
            }, 1000, false); //Playing with the time parameter does not change behavior.
        }
    }
    

    This gives exactly the same results. After that, I came to this post where @peter_strange

    provides a solution based on pushing a dummy screen, which detects the new width and height, and then passing the new values to the previous screen. I also tried, but it didn't work either.

    I also tried using the obsolete Graphics.getscreenWidth instead of Display.getWidth, and it did not work.

    Now, I am out of luck because I have almost tried everything and I can't provide a solution without resorting to the 4.7 or 6.0 API.

    Tested in BB 9550 Simulator v5.0.0.535 (Platform 2.13.0.108) and v5.0.0.306 real unit BB 9520 (Platform 4.2.0.113)

    Take a look at the following.  In my view, the following code can be used to detect changes in orientation.

    public class TestScreen extends MainScreen {
    
        int currentDisplayWidth = Display.getWidth();
        int currentDisplayOrientation = Display.getOrientation();
    
        public TestScreen(){
            super(Manager.NO_VERTICAL_SCROLL);
            populatescreen();
        }
    
        private void populatescreen(){
            deleteAll();
            //fields and containers added here. No need to add any to observe the issue.
        }
    
        public void sublayout(int width, int height){
            super.sublayout(width,height); //Tried calling this in the last line as well with identical result.     
    
            System.out.println(">>>>>>>>> Current sublayout width (before): " + currentDisplayWidth);
            System.out.println(">>>>>>>>> Display.getWidth(before): " + Display.getWidth());
            System.out.println(">>>>>>>>> Display.getOrientation(before): " + Display.getOrientation());
            System.out.println(">>>>>>>>> Width argument value (before): " + width);
            if ( Display.getWidth() != currentDisplayWidth ) {
                // process orientation change
                // ....
                // Now reset change detection variables.....
                currentDisplayWidth = Display.getWidth();
                currentDisplayOrientation = Display.getOrientation();
            }
        }
    }
    
  • Blocking rotation of the screen - 4.6.1 SDK

    Follow the latest code I did:

    What's up guys!
    I'm trying to run an application on curve 8520 and tourch 9800, so I use sdk4.6.1.
    I would block the rotation of the screen on the torch, but I know that the 4.6 SDK is no such API. I tried to override the paint method and invalidate sublayout, trying to put the paintSuspend as true.
    I need, in addition to block rotation, ask the user to return to the correct orientation (portrait), but dialogue does not work.

    My last code below:

    public final class MyScreen extends MainScreen {
     ...
     public void invalidate() {
            String deviceName = DeviceInfo.getDeviceName();
            int width = Display.getWidth();
            int height = Display.getHeight();
    
            System.out.println("diogo ------------display: " + width + " " + height + " name" + deviceName);
    
            if (width == 480 && height == 360 && deviceName.equalsIgnoreCase("9800")) {
    
                synchronized (UiApplication.getEventLock()) {
    
                    loadingDialog.setEscapeEnabled(false);
                    loadingDialog.doModal();
    
                    UiApplication.getUiApplication().suspendPainting(true);
                    System.out.println(UiApplication.getUiApplication().isPaintingSuspended());
    
                    return;
    
                }
            } else {
                if (UiApplication.getUiApplication().isPaintingSuspended())
                    UiApplication.getUiApplication().suspendPainting(false);
                loadingDialog.close();
            }
            super.invalidate();
        }
    }
    

    Might be easier to upgrade your 8520 for OS 5.0!

    I looked at your code seriously not, but invalid do seems to be a dangerous place to do so.

    I'd do it in sublayout.  sublayout is called when the rotation is detected.

    If you detect a rotation, then to sublayout, create an invokeLater (you will not be able to do this kind of thing in sublayout, you must start a new process).  The invokeLater push a new screen of your production.  In sublayout of the screen, check the orientation by using the width and height.  When that detects the correct orientation. have pop himself (in another invokeLater.  I think it should work and hooks in a defined place.

    Ask if this is not clear.

  • Screen rotation is the X 30 support for external displays?

    Yes... I know the X 30 is old school...

    but I use it for my presentation machine and it works well... and... If he was hit or swept, office

    I wouldn't feel so bad...

    In any case, I have the latest driver installed on my X 30 XP Professional Intel

    Video chipset is 82830M and I have the video bios 2691

    There is no tab in the properties panel video for "rotation" of the monitor,

    and nothing in the bios of the machine that controls this feature as I can see,

    so I guess the screen rotation is not supported on the X 30,

    but thought I would ask in case Miss me something obvious!

    Thank you!

    Hi jwooden,

    It is not natively supported, but this will work.  It is not free, but there is a 30 day free trial and the alignment of trackpoint will be on the side.

    I used to have a 30 x, son of my girlfriend now has.  He always uses it for school. I've always loved.

    Dave

  • Cliq: No automatic rotation when the load

    So, I hope that it is easy and the operator error, but I found that my auto-rotation of the screen does what he wants to when the phone is charging. I will notice you that when I take the camera, that he seems to always want to orient horizontally when I'm holding the camera vertically. Everyone has noticed this, is there maybe a reason for him and how to fix it? Help?


  • Animate using rotation and the puppet tool. Continuously rasterize mess it upward.

    In After Effects CC... Trying to animate a vector arms using rotation and the puppet tool. The animation looks good until I hit the button to rasterize continuously on this layer. He then gets distorted and cut out. I need to be continuously rasterized, so it's not pixelated.  Any suggestions on how to solve this would be great.

    In simple terms the effect of pupet pin uses space Composition and an alpha chanel of the first image to distort the pixels on the screen. So if you move or change the position or scale of the pixels after the first image to the assistance of any transformation or the effect, you now moved the original source of the pixels and puppets pin breaks. That's how the effect is designed and it's the only way it works.

    There is only a single correct workflow. Set up a model that is large enough to include all of the image that you want to animate when played back on the scale of 100% or a distance from the unit corresponding to the value of the camera zoom, if you size your layer of pine puppets if used in a comp. 3D IOW exceeds 100 percent in the final model, your computer is not big enough , or in a 3D model, if you want to move the camera at 1/4 the distance of the Zoom value of the camera to the layer of puppet pin your model of puppet PIN must be 4 times bigger.

    Animate the effect of pin puppet

    Bring the composition of spindle of puppets in yoiur main composition and apply other effects, transformations or any other manipulation, you need to perform to achieve your desired results.

    Puppet PIN is designed for this workflow and when used properly it is a very practical tool.

  • How to activate the rotation on the Windows Photo Viewer buttons?

    Original title: Rotation buttons

    How to activate the rotation on the Windows Photo Viewer buttons?

    Do you mean that the spin button is disable as if gray/disappear?

  • Locale in the Cascades Momentics model code is broken. Here is the solution...

    The Momentics application, it is easy to start new projects by basing your new application on a predefined model. The problem is that the regional settings, change the code in the application model Cascades do not work properly and developers who don't understand this will serve strings bad language to their users. The locale of the model code looks like this...

    void ApplicationUI::onSystemLanguageChanged() {    QCoreApplication::instance()->removeTranslator( this->_translator );
    
        // ---Initiate, load and install the application translation files.
        QString locale_string = QLocale().name();
        QString file_name = QString( "AppName_%1" ).arg( locale_string );
        if ( this->_translator->load( file_name, "app/native/qm" ) ) {
            QCoreApplication::instance()->installTranslator( this->_translator );
        }
    }
    

    The problem is that QLocale () .name () returns the region code by DEFAULT to the language setting of the user device, ignore the region on the device setting. For example, with the language set to English device and the region set to 'United States (English)', 'United Kingdom (English),' "(English) Canada" or "Australia (English)", QLocale () .name () will ALWAYS return en_US. Similarly, with the device language set to French, and the region, the value 'Canada (French)', QLocale () .name () will return en_US, not fr_CA as it should. It is behavior actually expected QLocale, not only in the Cascades, but in Qt ordinary too.

    The solution is simple. Rather than QLocale () .name () you use QLocale::system().name() instead, which fills a QLocale with the setting of the unit in the region, not only the language CORRECTLY. The code above should be...

    void ApplicationUI::onSystemLanguageChanged() {    QCoreApplication::instance()->removeTranslator( this->_translator );
    
        // ---Initiate, load and install the application translation files.
        QString locale_string = QLocale::system().name();
        QString file_name = QString( "AppName_%1" ).arg( locale_string );
        if ( this->_translator->load( file_name, "app/native/qm" ) ) {
            QCoreApplication::instance()->installTranslator( this->_translator );
        }
    }
    

    I suspect that there are hundreds of BB10 apps out there using the code of the default model where developers can't read the languages that they located, and so they do not realize that French Canadian users get the Parisian French translation, for example. It's not so bad with English, French, Spanish, etc., where variants are close enough to the base language, but the regional variants of Chinese are in fact completely different languages.

    In any case, type a few extra characters in a single line of your application code will solve this problem. Now if only we could get the Momentics model updated with the hotfix.

    After I posted the original explanation in this thread, I realized that handling locale of the waterfall model is still more broken that I realized the original. I noticed that, although incomplete, the model code would address changes for the system language settings, but he completely ignored changes in the region during the execution of the application. My original fix the problem repairs where the region has been completely ignored, but she does not answer that becomes the region while the application is running has no effect on the text displayed in the application.

    This means that if the user changes of American English in the English-speaking Canada, while the application is running the application will continue to display American English until it is restarted. It's particularly bad, if the system language is Chinese, as changing the region can result in a totally different language. It has proved to be more sensitive to this problem than I expected, but here's what you need to do to make your application respond to changes in the region put in too.

    The first thing to know is that there are two LocaleHandler classes in Cascades, and they perform different functions related though. One that is used in the model code is defined in , but one that we must manage changes in region is defined by . The fact that we have two classes with the same name in our application means that we explicitly specify that we speak and cannot if press "using namespace" condense our code.

    It's the language Manager changed the system (including the difficulty I described above)...

    void ApplicationUI::onSystemLanguageChanged()
    {
        QCoreApplication::instance()->removeTranslator(m_pTranslator);
    
        // Initiate, load and install the application translation files.
        QString locale_string = QLocale::system().name();
        QString file_name = QString("AppName_%1").arg(locale_string);
        if (m_pTranslator->load(file_name, "app/native/qm")) {
            QCoreApplication::instance()->installTranslator(m_pTranslator);
        }
    }
    

    Let's change this code to that...

    void ApplicationUI::onSystemLanguageChanged() {
        this->setLocale( QLocale::system().name() );
    }
    
    void ApplicationUI::onRegionChanged() {
        bb::system::LocaleHandler* localHandler = qobject_cast( sender() );
    
        this->setLocale( localHandler->locale().name() );
    }
    
    void ApplicationUI::setLocale( const QString& locale ) {
        QCoreApplication::instance()->removeTranslator( this->_translator );
    
        // ---Initiate, load and install the application translation files.
        QString file_name = QString( "AppName_%1" ).arg( locale );
        if ( this->_translator->load( file_name, "app/native/qm" ) ) {
            QCoreApplication::instance()->installTranslator( this->_translator );
        }
    }
    

    He must also change the code in the constructor of ApplicationUI of this...

    ApplicationUI::ApplicationUI() {
        // prepare the localization
        m_pTranslator = new QTranslator(this);
        m_pLocaleHandler = new LocaleHandler(this);
    
        bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));    // This is only available in Debug builds    Q_ASSERT(res);
    }
    

    .. .for this...

    ApplicationUI::ApplicationUI() {
        // prepare the localization
        m_pTranslator = new QTranslator(this);
        m_pLocaleHandler = new bb::cascades::LocaleHandler(this);
    
        bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
        // This is only available in Debug builds
        Q_ASSERT(res);
    
        bb::system::LocaleHandler* systemLocaleHandler = new bb::system::LocaleHandler( LocaleType::Region, this );    success = QObject::connect( systemLocaleHandler, SIGNAL( changed() ), SLOT( onRegionChanged() ) );    Q_ASSERT( success );
    }
    

    Once you have made any changes your app will meet changes in the region and the language system changes. Note that I don't provide code so that changes to the ApplicationUI.hpp to support the changes above, but rather than leave it to the reader.

  • Native of filebrowse using and the cascading Save dialog box

    In my application I need to open file and file save dialog box when a specific button is clicked. I looked at the docs of stunts, but I found that the native options. Tried the native alert dialog, change of filebrowse dialog type. It displays well on Simulator, but could not get any output file that will be used in the Qt code.

    I pass these parameters

    int * num = NULL;

    char * folder [1024];
    dialog_update (alert_dialog);

    to dialog_event_get_filebrowse_filepaths(event,file,num), but it always returns BPS_FAILURE.

    In addition, access_shared is present in the bar-descriptor

    Here is my code:

    //slot function
    void App::fileOpen(){
        //===========================
            dialog_instance_t alert_dialog = 0;
    
            bps_initialize();
    
            dialog_request_events(0);    //0 indicates that all events are requested
    
            if (dialog_create_filebrowse(&alert_dialog) != BPS_SUCCESS) {
                        fprintf(stderr, "Failed to create alert dialog.");
                        return ;
                }
                const char* extensions[] = {"*.*","*.jpg","*.jpeg","*.mp3","*.wav","*.mp4","*.txt","*.doc","*.pdf"};
                int items = 9;
                if(dialog_set_filebrowse_filter(alert_dialog, extensions,items) != BPS_SUCCESS){
                    fprintf(stderr, "Failed to set alert dialog message text.");
                            dialog_destroy(alert_dialog);
                           alert_dialog = 0;
                           return ;
                }
               if( dialog_set_filebrowse_multiselect(alert_dialog,FALSE)!=BPS_SUCCESS){
                   fprintf(stderr, "Failed to set alert dialog message text.");
                                dialog_destroy(alert_dialog);
                               alert_dialog = 0;
                               return ;
               }
    
            if (dialog_show(alert_dialog) != BPS_SUCCESS) {
                fprintf(stderr, "Failed to show alert dialog.");
                dialog_destroy(alert_dialog);
                alert_dialog = 0;
                return ;
            }
    
            int shutdown =0;
            while (!shutdown) {
                bps_event_t *event = NULL;
                bps_get_event(&event, -1);    // -1 means that the function waits
                                              // for an event before returning
    
                if (event) {
                    if (bps_event_get_domain(event) == dialog_get_domain()) {
    
                        int selectedIndex =
                            dialog_event_get_selected_index(event);
                        const char* label =
                            dialog_event_get_selected_label(event);
                        const char* context =
                            dialog_event_get_selected_context(event);
    
                        char **fileArray[]={};
                        int *numFiles = NULL;
                       //
                              if(selectedIndex == 0){
           shutdown = 1;//user press the cancel button on dialog; close the dialog
       }
       else if(selectedIndex == 1){
           if(dialog_event_get_filebrowse_filepaths(event,file,num)!=BPS_SUCCESS){
           fprintf(stderr,"File open fail");
       }
       else{
    
    //debug purposes
           fprintf(stderr,"File array: %d/n",sizeof(file)*1024);
               fprintf(stderr,"Num files: %n",num);
               //fprintf(stderr,"Files int: %d",files);
       }
    
       }
                    }
                }
            }
    
            if (alert_dialog) {
                dialog_destroy(alert_dialog);
            }
            //===========================
    }
    

    Native Subforums have no useful information on this subject. Any help is greatly appreciated

    Hello again, here's the example as promised.

    To use the native filebrowse dialog box, the native code must run in its own thread to prevent the user interface in the Cascades to block. This is achieved by encapsulating all the dialog box code in a class derived from QThread.  The class I wrote is called FileBrowseDialog

    FileBrowseDialog.hpp

    #ifndef FILEBROWSEDIALOG_HPP_
    #define FILEBROWSEDIALOG_HPP_
    
    #include 
    #include 
    #include 
    
    /*
     * The file browse dialog displays a dialog to browse and select
     * files from shared folders on the system.
     */
    class FileBrowseDialog : public QThread
    {
        Q_OBJECT
    
        /*
         * QML property to allow multiple selection
         */
        Q_PROPERTY(bool multiselect READ getMultiSelect WRITE setMultiSelect)
    
        /*
         * QML property to read the selected filenames
         */
        Q_PROPERTY(QVariant filepaths READ getFilePaths)
    
        /*
         * QML property to set or get the file filters. This is an
         * list array variant.
         */
        Q_PROPERTY(QVariant filters READ getFilters WRITE setFilters)
    public:
        /*
         * Ctor and Dtor
         */
        FileBrowseDialog(QObject* parent = 0);
        virtual ~FileBrowseDialog();
    
        /*
         * Exposed to QML to start the run loop which creates and displays the dialog.
         * The dialog is shown until a button is clicked.
         */
        Q_INVOKABLE void show();
    
    public:
        /*
         * Getter for the selected filenames QML property
         */
        QVariant getFilePaths() const;
    
        /*
         * Setter and Getter for the filters QML property
         */
        QVariant getFilters() const;
        void setFilters(QVariant const& value);
    
        /*
         * Getter and Setter for the multiselect QML property
         */
        bool getMultiSelect() const;
        void setMultiSelect(bool value);
    
    signals:
        /*
         * Signal emitted when the OK button has been clicked on the browse dialog
         * The OK button is not enabled unless a file is selected
         */
        void selectionCompleted();
    
        /*
         * Signal emitted when the cancel button has been clicked on the browse dialog
         */
        void selectionCancelled();
    
    protected:
        /*
         * Implements the run loop. Dialog stays open until a button is clicked.
         */
        virtual void run();
    
    protected:
        dialog_instance_t m_dialog;
        bool m_multiSelect;
        QVariantList m_filePaths;
        QVariantList m_filters;
    };
    
    #endif /* FILEBROWSEDIALOG_HPP_ */
    

    FileBrowseDialog.cpp

    #include "FileBrowseDialog.hpp"
    #include 
    #include 
    
    FileBrowseDialog::FileBrowseDialog(QObject* parent)
        : QThread(parent)
        , m_multiSelect(false)
    {
        m_filters.push_back(QString("*.*"));
    }
    
    FileBrowseDialog::~FileBrowseDialog()
    {
    }
    
    void FileBrowseDialog::show()
    {
        if (!isRunning())
        {
            m_filePaths.clear();
            start();
        }
    }
    
    QVariant FileBrowseDialog::getFilePaths() const
    {
        return m_filePaths;
    }
    
    bool FileBrowseDialog::getMultiSelect() const
    {
        return m_multiSelect;
    }
    
    void FileBrowseDialog::setMultiSelect(bool value)
    {
        m_multiSelect = value;
    }
    
    QVariant FileBrowseDialog::getFilters() const
    {
        return m_filters;
    }
    
    void FileBrowseDialog::setFilters(QVariant const& value)
    {
        m_filters = value.toList();
        qDebug() << "filter count: " << m_filters.count();
    }
    
    void FileBrowseDialog::run()
    {
        bps_initialize();
    
        //request all dialog events
        dialog_request_events(0);
        if (dialog_create_filebrowse(&m_dialog) != BPS_SUCCESS)
        {
            qDebug() << "Failed to create file browse dialog.";
            emit selectionCancelled();
            return;
        }
    
        //set the selection filters
        if (m_filters.count() > 0)
        {
            char** ext = (char**)new char[m_filters.count()*sizeof(char*)];
            int i = 0;
            for (QVariantList::iterator it = m_filters.begin(); it != m_filters.end(); ++it, ++i)
            {
                QString filter = it->toString();
                if (!filter.trimmed().isEmpty())
                {
                    int length = (filter.length() + 1) * sizeof(char);
                    ext[i] = new char[length];
                    strncpy(ext[i], filter.toAscii(), length);
                }
            }
            if (dialog_set_filebrowse_filter(m_dialog, (const char**)ext, m_filters.count()) != BPS_SUCCESS)
            {
                qDebug() << "unable to set file browse dialog extensions";
            }
            for (i = 0; i < m_filters.count(); i++)
            {
                delete ext[i];
            }
            delete ext;
        }
    
        if (dialog_show(m_dialog) != BPS_SUCCESS)
        {
            qDebug() << "Failed to show file browse dialog.";
            dialog_destroy(m_dialog);
            m_dialog = 0;
            emit selectionCancelled();
            return;
        }
    
        bool shutdown = false;
        while (!shutdown)
        {
            bps_event_t* event = NULL;
            bps_get_event(&event, -1);    // -1 means that the function waits
            // for an event before returning
    
            if (event)
            {
                if (bps_event_get_domain(event) == dialog_get_domain())
                {
                    //0=ok, 1=cancel
                    int selectedIndex = dialog_event_get_selected_index(event);
    
                    if (selectedIndex == 1)
                    {
                        int count;
                        char** filepaths;
                        if (BPS_SUCCESS == dialog_event_get_filebrowse_filepaths(event, &filepaths, &count))
                        {
                            for (int i = 0; i < count; i++)
                            {
                                qDebug() << "selected file: " << filepaths[i];
                                m_filePaths.push_back(QString(filepaths[i]));
                            }
                            bps_free(filepaths);
                        }
                        emit selectionCompleted();
                    }
                    else
                    {
                        emit selectionCancelled();
                    }
    
                    qDebug() << "Got file browse dialog click";
                    shutdown = true;
                }
            }
        }
    
        if (m_dialog)
        {
            dialog_destroy(m_dialog);
        }
    }
    

    This class derives from QObject (by QThread) which means that it can be used by QML when it exposes properties and signals. The FileBrowseDialog class has 3 properties

    -multiple selection: a Boolean flag indicating if single or multiple selection is allowed

    -filepaths: a read only value that returns the list of files selected

    -Filters: a read/write value is where you can specify one or more filters to file (for example, ".doc", "*.jpg") etc.

    The next part is how you call the FileBrowseDialog through the QML. To do this, we must inform the QML of the FileBrowseDialog page. This is done in the App class via the qmlregistertype code.

    App.cpp

    #include 
    #include 
    #include 
    
    #include "app.hpp"
    #include "FileBrowseDialog.hpp"
    
    using namespace bb::cascades;
    
    App::App()
    {
        qmlRegisterType("Dialog.FileBrowse", 1, 0, "FileBrowseDialog");
        QmlDocument *qml = QmlDocument::create("main.qml");
        qml->setContextProperty("cs", this);
    
        AbstractPane *root = qml->createRootNode();
        Application::setScene(root);
    }
    

    The QML is now ready to be able to use the FileBrowseDialog. The example below is a page complete qml which has a button and a label. When we click on the FileBrowseDialog button is open, and all selected files will appear in the label.

    Main.QML

    import bb.cascades 1.0
    import Dialog.FileBrowse 1.0
    
    Page {
        content: Container {
            Label { id: filebrowseDialogLabel }
            Button {
                text : "File Browse Dialog"
                onClicked: {
                    filebrowseDialog.show();
                }
            }
            attachedObjects: [
                FileBrowseDialog {
                    id: filebrowseDialog
                    multiselect : true
                    filters : ["*.doc","*.jpg","*.txt"]
                    onSelectionCompleted: {
                        if(filebrowseDialog.filepaths.length>0)
                            filebrowseDialogLabel.text = filebrowseDialog.filepaths[0];
                        else
                            filebrowseDialogLabel.text = "no file selected";
                    }
                    onSelectionCancelled: {
                        filebrowseDialogLabel.text = "file browse dialog was cancelled";
                    }
                }
            ]
        }
    }
    

    And it's pretty much just invoke the native dialog file navigation in stunts. Please note save the file would follow a similar model, but I found that this dialog box was not particularly useful because it displays only a simple dialogbox with a text file name entry.

    See you soon

    Swann

  • Rotation of the device

    which method was callen after the rotation of the device?

    Or how I could change my interface after the rotation of the device?

    sublayout is called as the dimensions change.

    You can also use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/AccelerometerListener.h... listening to the changes, but you want to update the method of sublayout interface would be easier.

  • Redraw the images after the rotation of the device

    Hi, all)

    I need redesign my interphace after the rotation of the device...

    I have a method in myScreen,

    public LoginScreen()
    {
    scaleKoof = Display.getWidth () / 320.0f;
    Create the interface elements

    }

    If I coluld call it after rotating all might be good! How can I do?

    scaleRotation - all images are resized to my interpace...

    replace sublayout and check the dimensions, it is called after a rotation.

Maybe you are looking for